1#![allow(non_snake_case)]
37#![allow(unused_variables)]
38#![allow(clippy::missing_safety_doc)]
39#![allow(clippy::not_unsafe_ptr_arg_deref)]
40
41use core::ffi::c_void;
42use core::ptr;
43use once_cell::sync::Lazy;
44use parking_lot::Mutex;
45use std::collections::HashMap;
46use std::ffi::CStr;
47use std::mem::size_of;
48use std::os::raw::{c_char, c_int, c_uint};
49
50use crate::xml::xinclude;
51use crate::xml::xpath::ast::CompiledExpr;
52use crate::xml::xpath::context::XPathContext;
53use crate::xml::xpath::types::{NodeSet, XPathValue};
54use crate::xml::xpointer;
55
56use crate::abi::allocator::*;
57use crate::abi::callbacks::*;
58use crate::abi::structs::*;
59use crate::abi::types::*;
60
61#[no_mangle]
76pub unsafe extern "C" fn xmlInitParser() {
77 crate::internal::globals::init_parser();
78}
79
80#[no_mangle]
90pub unsafe extern "C" fn xmlCleanupParser() {
91 crate::internal::globals::cleanup_parser();
92}
93
94#[no_mangle]
104pub unsafe extern "C" fn xmlInitThreads() -> c_int {
105 crate::internal::globals::init_threads()
106}
107
108#[no_mangle]
116pub unsafe extern "C" fn xmlCleanupThreads() {
117 crate::xml::threads::cleanup_threads();
118}
119
120#[no_mangle]
128pub extern "C" fn xmlIsInitialized() -> c_int {
129 if crate::abi::versioning::is_initialized() {
130 1
131 } else {
132 0
133 }
134}
135
136#[no_mangle]
145pub unsafe extern "C" fn xmlLockLibrary() {
146 crate::xml::threads::lock_library();
147}
148
149#[no_mangle]
157pub unsafe extern "C" fn xmlUnlockLibrary() {
158 crate::xml::threads::unlock_library();
159}
160
161#[no_mangle]
178pub unsafe extern "C" fn xmlSetGenericErrorFunc(
179 ctx: *mut c_void,
180 handler: Option<xmlGenericErrorFunc>,
181) {
182 unsafe { crate::xml::errors::set_generic_error_func(ctx, handler) };
184}
185
186#[no_mangle]
198pub unsafe extern "C" fn xmlSetStructuredErrorFunc(
199 ctx: *mut c_void,
200 handler: Option<xmlStructuredErrorFunc>,
201) {
202 unsafe { crate::xml::errors::set_structured_error_func(ctx, handler) };
204}
205
206#[no_mangle]
217pub extern "C" fn xmlGetLastError() -> *mut _xmlError {
218 crate::xml::errors::get_last_error()
219}
220
221#[no_mangle]
235pub unsafe extern "C" fn xmlCopyError(from: *const _xmlError, to: *mut _xmlError) -> c_int {
236 unsafe { crate::xml::errors::copy_error(from, to) }
238}
239
240#[no_mangle]
252pub unsafe extern "C" fn xmlResetError(err: *mut _xmlError) {
253 unsafe { crate::xml::errors::reset_error(err) };
255}
256
257#[no_mangle]
270pub unsafe extern "C" fn xmlRaiseError(
271 ctxt: *mut c_void,
272 ctxt2: *mut c_void,
273 ctxt3: *mut c_void,
274 ctxt4: *mut c_void,
275 ctxt5: *mut c_void,
276 domain: c_int,
277 code: c_int,
278 level: c_int,
279 file: *const c_char,
280 line: c_int,
281 str1: *const c_char,
282 str2: *const c_char,
283 str3: *const c_char,
284 int1: c_int,
285 int2: c_int,
286 msg: *const c_char,
287) {
288 unsafe {
290 crate::xml::errors::raise_error(
291 ctxt, ctxt2, ctxt3, ctxt4, ctxt5, domain, code, level, file, line, str1, str2, str3,
292 int1, int2, msg,
293 );
294 }
295}
296
297#[no_mangle]
305pub extern "C" fn xmlResetLastError() {
306 crate::xml::errors::reset_last_error();
307}
308
309#[no_mangle]
325pub unsafe extern "C" fn xmlStrdup(cur: *const xmlChar) -> *mut xmlChar {
326 if cur.is_null() {
327 return ptr::null_mut();
328 }
329 let len = unsafe { xmlStrlen(cur) };
330 let size = len + 1;
331 let new_ptr = unsafe { xmlMalloc(size as usize) };
332 if new_ptr.is_null() {
333 return ptr::null_mut();
334 }
335 unsafe {
336 ptr::copy_nonoverlapping(cur as *const u8, new_ptr as *mut u8, size as usize);
337 }
338 new_ptr as *mut xmlChar
339}
340
341#[no_mangle]
353pub unsafe extern "C" fn xmlStrndup(cur: *const xmlChar, len: c_int) -> *mut xmlChar {
354 if cur.is_null() || len <= 0 {
355 return ptr::null_mut();
356 }
357 let size = len as usize + 1;
358 let new_ptr = unsafe { xmlMalloc(size) };
359 if new_ptr.is_null() {
360 return ptr::null_mut();
361 }
362 unsafe {
363 ptr::copy_nonoverlapping(cur as *const u8, new_ptr as *mut u8, len as usize);
364 *(new_ptr.add(len as usize) as *mut u8) = 0;
365 }
366 new_ptr as *mut xmlChar
367}
368
369#[no_mangle]
381pub unsafe extern "C" fn xmlStrlen(str: *const xmlChar) -> c_int {
382 if str.is_null() {
383 return 0;
384 }
385 unsafe { libc::strlen(str as *const c_char) as c_int }
386}
387
388#[no_mangle]
399pub unsafe extern "C" fn xmlStrcmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
400 if str1.is_null() && str2.is_null() {
401 return 0;
402 }
403 if str1.is_null() {
404 return -1;
405 }
406 if str2.is_null() {
407 return 1;
408 }
409 unsafe { libc::strcmp(str1 as *const c_char, str2 as *const c_char) as c_int }
410}
411
412#[no_mangle]
420pub unsafe extern "C" fn xmlStrncmp(
421 str1: *const xmlChar,
422 str2: *const xmlChar,
423 len: c_int,
424) -> c_int {
425 if len <= 0 {
426 return 0;
427 }
428 if str1.is_null() && str2.is_null() {
429 return 0;
430 }
431 if str1.is_null() {
432 return -1;
433 }
434 if str2.is_null() {
435 return 1;
436 }
437 unsafe { libc::strncmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int }
438}
439
440#[no_mangle]
448pub unsafe extern "C" fn xmlStrcasecmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
449 if str1.is_null() && str2.is_null() {
450 return 0;
451 }
452 if str1.is_null() {
453 return -1;
454 }
455 if str2.is_null() {
456 return 1;
457 }
458 unsafe { libc::strcasecmp(str1 as *const c_char, str2 as *const c_char) as c_int }
459}
460
461#[no_mangle]
469pub unsafe extern "C" fn xmlStrncasecmp(
470 str1: *const xmlChar,
471 str2: *const xmlChar,
472 len: c_int,
473) -> c_int {
474 if len <= 0 {
475 return 0;
476 }
477 if str1.is_null() && str2.is_null() {
478 return 0;
479 }
480 if str1.is_null() {
481 return -1;
482 }
483 if str2.is_null() {
484 return 1;
485 }
486 unsafe {
487 libc::strncasecmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int
488 }
489}
490
491#[no_mangle]
501pub unsafe extern "C" fn xmlStrEqual(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
502 if str1.is_null() && str2.is_null() {
503 return 1;
504 }
505 if str1.is_null() || str2.is_null() {
506 return 0;
507 }
508 unsafe { (libc::strcmp(str1 as *const c_char, str2 as *const c_char) == 0) as c_int }
509}
510
511#[no_mangle]
522pub unsafe extern "C" fn xmlStrQEqual(
523 pref: *const xmlChar,
524 name: *const xmlChar,
525 str: *const xmlChar,
526) -> c_int {
527 if name.is_null() || str.is_null() {
528 return 0;
529 }
530 if pref.is_null() {
531 return unsafe { xmlStrEqual(name, str) };
532 }
533 let pref_len = unsafe { xmlStrlen(pref) };
535 let name_len = unsafe { xmlStrlen(name) };
536 let total_len = pref_len + 1 + name_len;
537 let str_len = unsafe { xmlStrlen(str) };
538 if total_len != str_len {
539 return 0;
540 }
541 if unsafe {
543 libc::strncmp(
544 pref as *const c_char,
545 str as *const c_char,
546 pref_len as usize,
547 )
548 } != 0
549 {
550 return 0;
551 }
552 if unsafe { *str.add(pref_len as usize) } != b':' as xmlChar {
554 return 0;
555 }
556 (unsafe {
558 libc::strncmp(
559 name as *const c_char,
560 str.add((pref_len + 1) as usize) as *const c_char,
561 name_len as usize,
562 ) == 0
563 }) as c_int
564}
565
566#[no_mangle]
580pub unsafe extern "C" fn xmlStrcat(cur: *mut xmlChar, add: *const xmlChar) -> *mut xmlChar {
581 if add.is_null() {
582 return cur;
583 }
584 if cur.is_null() {
585 return unsafe { xmlStrdup(add) };
586 }
587 let cur_len = unsafe { xmlStrlen(cur) } as usize;
588 let add_len = unsafe { xmlStrlen(add) } as usize;
589 let new_size = cur_len + add_len + 1;
590 let new_ptr = unsafe { xmlRealloc(cur as *mut c_void, new_size) };
591 if new_ptr.is_null() {
592 return ptr::null_mut();
593 }
594 unsafe {
595 ptr::copy_nonoverlapping(add as *const u8, (new_ptr as *mut u8).add(cur_len), add_len);
596 *((new_ptr as *mut u8).add(cur_len + add_len)) = 0;
597 }
598 new_ptr as *mut xmlChar
599}
600
601#[no_mangle]
613pub unsafe extern "C" fn xmlStrncat(
614 cur: *mut xmlChar,
615 add: *const xmlChar,
616 len: c_int,
617) -> *mut xmlChar {
618 if add.is_null() || len <= 0 {
619 return cur;
620 }
621 let len = len as usize;
622 if cur.is_null() {
623 return unsafe { xmlStrndup(add, len as c_int) };
624 }
625 let cur_len = unsafe { xmlStrlen(cur) } as usize;
626 let new_size = cur_len + len + 1;
627 let new_ptr = unsafe { xmlRealloc(cur as *mut c_void, new_size) };
628 if new_ptr.is_null() {
629 return ptr::null_mut();
630 }
631 unsafe {
632 ptr::copy_nonoverlapping(add as *const u8, (new_ptr as *mut u8).add(cur_len), len);
633 *((new_ptr as *mut u8).add(cur_len + len)) = 0;
634 }
635 new_ptr as *mut xmlChar
636}
637
638#[no_mangle]
646pub unsafe extern "C" fn xmlStrncatNew(
647 str1: *const xmlChar,
648 str2: *const xmlChar,
649 len: c_int,
650) -> *mut xmlChar {
651 let mut result: *mut xmlChar = ptr::null_mut();
652 if !str1.is_null() {
653 result = unsafe { xmlStrdup(str1) };
654 }
655 if !str2.is_null() && len > 0 {
656 result = unsafe { xmlStrncat(result, str2, len) };
657 }
658 result
659}
660
661#[no_mangle]
674pub unsafe extern "C" fn xmlStrcpy(dst: *mut xmlChar, src: *const xmlChar) -> *mut xmlChar {
675 if dst.is_null() || src.is_null() {
676 return dst;
677 }
678 let len = unsafe { xmlStrlen(src) } as usize + 1;
679 unsafe {
680 ptr::copy_nonoverlapping(src as *const u8, dst as *mut u8, len);
681 }
682 dst
683}
684
685#[no_mangle]
693pub unsafe extern "C" fn xmlStrncpy(
694 dst: *mut xmlChar,
695 src: *const xmlChar,
696 len: c_int,
697) -> *mut xmlChar {
698 if dst.is_null() || src.is_null() || len <= 0 {
699 return dst;
700 }
701 let len = len as usize;
702 let src_len = unsafe { xmlStrlen(src) } as usize;
703 let copy_len = if src_len < len { src_len } else { len - 1 };
704 unsafe {
705 ptr::copy_nonoverlapping(src as *const u8, dst as *mut u8, copy_len);
706 *dst.add(copy_len) = 0;
707 }
708 dst
709}
710
711#[no_mangle]
721pub unsafe extern "C" fn xmlStrsub(str: *const xmlChar, start: c_int, len: c_int) -> *mut xmlChar {
722 if str.is_null() || start < 0 || len < 0 {
723 return ptr::null_mut();
724 }
725 let str_len = unsafe { xmlStrlen(str) };
726 if start >= str_len {
727 return unsafe { xmlStrdup(b"\0" as *const u8 as *const xmlChar) };
728 }
729 let actual_len = if start + len > str_len {
730 str_len - start
731 } else {
732 len
733 };
734 unsafe { xmlStrndup(str.add(start as usize), actual_len) }
735}
736
737#[no_mangle]
754pub unsafe extern "C" fn xmlNewDoc(version: *const xmlChar) -> *mut _xmlDoc {
755 crate::xml::tree::new_doc(version)
756}
757
758#[no_mangle]
770pub unsafe extern "C" fn xmlFreeDoc(doc: *mut _xmlDoc) {
771 crate::xml::tree::free_doc(doc);
772}
773
774#[no_mangle]
788pub unsafe extern "C" fn xmlNewNode(ns: *mut _xmlNs, name: *const xmlChar) -> *mut _xmlNode {
789 crate::xml::tree::new_node(ns, name)
790}
791
792#[no_mangle]
805pub unsafe extern "C" fn xmlFreeNode(node: *mut _xmlNode) {
806 crate::xml::tree::free_node(node);
807}
808
809#[no_mangle]
821pub unsafe extern "C" fn xmlUnlinkNode(node: *mut _xmlNode) {
822 crate::xml::tree::unlink_node(node);
823}
824
825#[no_mangle]
839pub unsafe extern "C" fn xmlAddChild(parent: *mut _xmlNode, cur: *mut _xmlNode) -> *mut _xmlNode {
840 crate::xml::tree::add_child(parent, cur)
841}
842
843#[no_mangle]
855pub unsafe extern "C" fn xmlAddSibling(
856 cur: *mut _xmlNode,
857 sibling: *mut _xmlNode,
858) -> *mut _xmlNode {
859 crate::xml::tree::add_sibling(cur, sibling)
860}
861
862#[no_mangle]
881pub unsafe extern "C" fn xmlNewChild(
882 parent: *mut _xmlNode,
883 ns: *mut _xmlNs,
884 name: *const xmlChar,
885 content: *const xmlChar,
886) -> *mut _xmlNode {
887 crate::xml::tree::new_child(parent, ns, name)
888}
889
890#[no_mangle]
905pub unsafe extern "C" fn xmlDocSetRootElement(
906 doc: *mut _xmlDoc,
907 root: *mut _xmlNode,
908) -> *mut _xmlNode {
909 crate::xml::tree::doc_set_root_element(doc, root)
910}
911
912#[no_mangle]
922pub extern "C" fn xmlDocGetRootElement(doc: *const _xmlDoc) -> *mut _xmlNode {
923 crate::xml::tree::doc_get_root_element(doc as *mut _xmlDoc)
924}
925
926#[no_mangle]
939pub unsafe extern "C" fn xmlCopyNode(node: *const _xmlNode, extended: c_int) -> *mut _xmlNode {
940 crate::xml::tree::copy_node(node, extended)
941}
942
943#[no_mangle]
953pub unsafe extern "C" fn xmlCopyDoc(doc: *const _xmlDoc, recursive: c_int) -> *mut _xmlDoc {
954 crate::xml::tree::copy_doc(doc, recursive)
955}
956
957#[no_mangle]
968pub unsafe extern "C" fn xmlNewText(content: *const xmlChar) -> *mut _xmlNode {
969 crate::xml::tree::new_text(content)
970}
971
972#[no_mangle]
980pub unsafe extern "C" fn xmlNewComment(content: *const xmlChar) -> *mut _xmlNode {
981 crate::xml::tree::new_comment(content)
982}
983
984#[no_mangle]
992pub unsafe extern "C" fn xmlNewPI(name: *const xmlChar, content: *const xmlChar) -> *mut _xmlNode {
993 crate::xml::tree::new_pi(name, content)
994}
995
996#[no_mangle]
1004pub unsafe extern "C" fn xmlNewCDataBlock(
1005 doc: *mut _xmlDoc,
1006 content: *const xmlChar,
1007 len: c_int,
1008) -> *mut _xmlNode {
1009 crate::xml::tree::new_cdata_block(doc, content, len)
1010}
1011
1012#[no_mangle]
1026pub unsafe extern "C" fn xmlNewNs(
1027 node: *mut _xmlNode,
1028 href: *const xmlChar,
1029 prefix: *const xmlChar,
1030) -> *mut _xmlNs {
1031 crate::xml::tree::new_ns(node, href, prefix)
1032}
1033
1034#[no_mangle]
1042pub unsafe extern "C" fn xmlSetNs(node: *mut _xmlNode, ns: *mut _xmlNs) {
1043 crate::xml::tree::set_ns(node, ns);
1044}
1045
1046#[no_mangle]
1054pub unsafe extern "C" fn xmlGetNsList(
1055 doc: *mut _xmlDoc,
1056 node: *const _xmlNode,
1057) -> *mut *mut _xmlNs {
1058 crate::xml::tree::get_ns_list(doc, node as *mut _xmlNode)
1059}
1060
1061#[no_mangle]
1069pub unsafe extern "C" fn xmlSearchNs(
1070 doc: *mut _xmlDoc,
1071 node: *mut _xmlNode,
1072 nameSpace: *const xmlChar,
1073) -> *mut _xmlNs {
1074 crate::xml::tree::search_ns(doc, node, nameSpace)
1075}
1076
1077#[no_mangle]
1085pub unsafe extern "C" fn xmlSearchNsByHref(
1086 doc: *mut _xmlDoc,
1087 node: *mut _xmlNode,
1088 href: *const xmlChar,
1089) -> *mut _xmlNs {
1090 crate::xml::tree::search_ns_by_href(doc, node, href)
1091}
1092
1093#[no_mangle]
1110pub unsafe extern "C" fn xmlSetProp(
1111 node: *mut _xmlNode,
1112 name: *const xmlChar,
1113 value: *const xmlChar,
1114) -> *mut _xmlAttr {
1115 crate::xml::tree::set_prop(node, name, value)
1116}
1117
1118#[no_mangle]
1128pub unsafe extern "C" fn xmlGetProp(node: *const _xmlNode, name: *const xmlChar) -> *mut xmlChar {
1129 crate::xml::tree::get_prop(node as *mut _xmlNode, name)
1130}
1131
1132#[no_mangle]
1140pub unsafe extern "C" fn xmlGetNsProp(
1141 node: *const _xmlNode,
1142 name: *const xmlChar,
1143 nameSpace: *const xmlChar,
1144) -> *mut xmlChar {
1145 crate::xml::tree::get_ns_prop(node as *mut _xmlNode, name, nameSpace)
1146}
1147
1148#[no_mangle]
1157pub unsafe extern "C" fn xmlSetNsProp(
1158 node: *mut _xmlNode,
1159 ns: *mut _xmlNs,
1160 name: *const xmlChar,
1161 value: *const xmlChar,
1162) -> *mut _xmlAttr {
1163 crate::xml::tree::set_ns_prop(node, ns, name, value)
1164}
1165
1166#[no_mangle]
1176pub unsafe extern "C" fn xmlRemoveProp(attr: *mut _xmlAttr) -> c_int {
1177 crate::xml::tree::remove_prop(attr)
1178}
1179
1180#[no_mangle]
1188pub extern "C" fn xmlGetIntSubset(doc: *const _xmlDoc) -> *mut _xmlDtd {
1189 crate::xml::tree::get_int_subset(doc)
1190}
1191
1192#[no_mangle]
1201pub unsafe extern "C" fn xmlNewDtd(
1202 doc: *mut _xmlDoc,
1203 name: *const xmlChar,
1204 ExternalID: *const xmlChar,
1205 SystemID: *const xmlChar,
1206) -> *mut _xmlDtd {
1207 crate::xml::tree::new_dtd(doc, name, ExternalID, SystemID)
1208}
1209
1210#[no_mangle]
1220pub unsafe extern "C" fn xmlNewEntity(
1221 doc: *mut _xmlDoc,
1222 name: *const xmlChar,
1223 type_: c_int,
1224 ExternalID: *const xmlChar,
1225 SystemID: *const xmlChar,
1226 content: *const xmlChar,
1227) -> *mut _xmlEntity {
1228 crate::xml::tree::new_entity(doc, name, type_, ExternalID, SystemID, content)
1229}
1230
1231#[no_mangle]
1239pub unsafe extern "C" fn xmlGetDocEntity(
1240 doc: *const _xmlDoc,
1241 name: *const xmlChar,
1242) -> *mut _xmlEntity {
1243 crate::xml::tree::get_doc_entity(doc, name)
1244}
1245
1246#[no_mangle]
1254pub unsafe extern "C" fn xmlGetParameterEntity(
1255 doc: *const _xmlDoc,
1256 name: *const xmlChar,
1257) -> *mut _xmlEntity {
1258 crate::xml::tree::get_parameter_entity(doc, name)
1259}
1260
1261#[no_mangle]
1272pub unsafe extern "C" fn xmlCreateIntSubset(
1273 doc: *mut _xmlDoc,
1274 name: *const xmlChar,
1275 ExternalID: *const xmlChar,
1276 SystemID: *const xmlChar,
1277) -> *mut _xmlDtd {
1278 crate::xml::dtd::create_int_subset(doc, name, ExternalID, SystemID)
1279}
1280
1281#[no_mangle]
1289pub unsafe extern "C" fn xmlFreeDtd(dtd: *mut _xmlDtd) {
1290 crate::xml::dtd::free_dtd(dtd);
1291}
1292
1293#[no_mangle]
1303pub unsafe extern "C" fn xmlAddNotationDecl(
1304 dtd: *mut _xmlDtd,
1305 name: *const xmlChar,
1306 PublicID: *const xmlChar,
1307 SystemID: *const xmlChar,
1308) -> *mut _xmlNotation {
1309 crate::xml::dtd::add_notation_decl(dtd, name, PublicID, SystemID)
1310}
1311
1312#[no_mangle]
1320pub unsafe extern "C" fn xmlGetNotationDecl(
1321 dtd: *mut _xmlDtd,
1322 name: *const xmlChar,
1323) -> *mut _xmlNotation {
1324 crate::xml::dtd::get_notation_decl(dtd, name)
1325}
1326
1327#[no_mangle]
1335pub unsafe extern "C" fn xmlCopyNotation(notation: *mut _xmlNotation) -> *mut _xmlNotation {
1336 crate::xml::dtd::copy_notation(notation)
1337}
1338
1339#[no_mangle]
1347pub unsafe extern "C" fn xmlFreeNotation(notation: *mut _xmlNotation) {
1348 crate::xml::dtd::free_notation(notation);
1349}
1350
1351#[no_mangle]
1360pub unsafe extern "C" fn xmlAddElementDecl(
1361 dtd: *mut _xmlDtd,
1362 name: *const xmlChar,
1363 type_: c_int,
1364 content: *mut _xmlElementContent,
1365) -> *mut _xmlElement {
1366 crate::xml::dtd::add_element_decl(dtd, name, type_, content)
1367}
1368
1369#[no_mangle]
1377pub unsafe extern "C" fn xmlGetElementDecl(
1378 dtd: *mut _xmlDtd,
1379 name: *const xmlChar,
1380) -> *mut _xmlElement {
1381 crate::xml::dtd::get_element_decl(dtd, name)
1382}
1383
1384#[no_mangle]
1392pub unsafe extern "C" fn xmlCopyElement(elem: *mut _xmlElement) -> *mut _xmlElement {
1393 crate::xml::dtd::copy_element(elem)
1394}
1395
1396#[no_mangle]
1404pub unsafe extern "C" fn xmlFreeElement(elem: *mut _xmlElement) {
1405 crate::xml::dtd::free_element(elem);
1406}
1407
1408#[no_mangle]
1419pub unsafe extern "C" fn xmlAddAttributeDecl(
1420 dtd: *mut _xmlDtd,
1421 elem: *mut _xmlElement,
1422 name: *const xmlChar,
1423 type_: c_int,
1424 def: c_int,
1425 defaultValue: *const xmlChar,
1426 tree: *mut _xmlEnumeration,
1427) -> *mut _xmlAttribute {
1428 crate::xml::dtd::add_attribute_decl(dtd, elem, name, type_, def, defaultValue, tree)
1429}
1430
1431#[no_mangle]
1440pub unsafe extern "C" fn xmlGetAttributeDecl(
1441 dtd: *mut _xmlDtd,
1442 elem: *mut _xmlElement,
1443 name: *const xmlChar,
1444 namePrefix: c_int,
1445) -> *mut _xmlAttribute {
1446 crate::xml::dtd::get_attribute_decl(dtd, elem, name, namePrefix)
1447}
1448
1449#[no_mangle]
1457pub unsafe extern "C" fn xmlCopyAttribute(attr: *mut _xmlAttribute) -> *mut _xmlAttribute {
1458 crate::xml::dtd::copy_attribute_decl(attr)
1459}
1460
1461#[no_mangle]
1469pub unsafe extern "C" fn xmlFreeAttribute(attr: *mut _xmlAttribute) {
1470 crate::xml::dtd::free_attribute(attr);
1471}
1472
1473#[no_mangle]
1481pub unsafe extern "C" fn xmlNewElementContent(
1482 name: *const xmlChar,
1483 type_: c_int,
1484) -> *mut _xmlElementContent {
1485 crate::xml::dtd::create_content_model(name, type_)
1486}
1487
1488#[no_mangle]
1496pub unsafe extern "C" fn xmlCopyElementContent(
1497 content: *mut _xmlElementContent,
1498) -> *mut _xmlElementContent {
1499 crate::xml::dtd::copy_content_model(content)
1500}
1501
1502#[no_mangle]
1510pub unsafe extern "C" fn xmlFreeElementContent(cur: *mut _xmlElementContent) {
1511 crate::xml::dtd::free_content_model(cur);
1512}
1513
1514#[no_mangle]
1526pub unsafe extern "C" fn xmlAddEntity(
1527 dtd: *mut _xmlDtd,
1528 name: *const xmlChar,
1529 type_: c_int,
1530 ExternalID: *const xmlChar,
1531 SystemID: *const xmlChar,
1532 content: *const xmlChar,
1533) -> *mut _xmlEntity {
1534 crate::xml::entities::add_entity(dtd, name, type_, ExternalID, SystemID, content)
1535}
1536
1537#[no_mangle]
1545pub unsafe extern "C" fn xmlGetEntity(doc: *mut _xmlDoc, name: *const xmlChar) -> *mut _xmlEntity {
1546 crate::xml::entities::get_entity(doc, name)
1547}
1548
1549#[no_mangle]
1557pub unsafe extern "C" fn xmlCopyEntity(entity: *mut _xmlEntity) -> *mut _xmlEntity {
1558 crate::xml::entities::copy_entity(entity)
1559}
1560
1561#[no_mangle]
1569pub unsafe extern "C" fn xmlFreeEntity(entity: *mut _xmlEntity) {
1570 crate::xml::entities::free_entity(entity);
1571}
1572
1573#[no_mangle]
1581pub unsafe extern "C" fn xmlEncodeEntitiesReentrant(
1582 doc: *mut _xmlDoc,
1583 input: *const xmlChar,
1584) -> *mut xmlChar {
1585 crate::xml::entities::encode_entities_reentrant(doc, input)
1586}
1587
1588#[no_mangle]
1596pub extern "C" fn xmlGetLineNo(node: *const _xmlNode) -> c_int {
1597 crate::xml::tree::get_line_no(node)
1598}
1599
1600#[no_mangle]
1612pub unsafe extern "C" fn xmlNodeDump(
1613 buf: *mut _xmlBuffer,
1614 doc: *mut _xmlDoc,
1615 cur: *mut _xmlNode,
1616 level: c_int,
1617 format: c_int,
1618) -> c_int {
1619 if buf.is_null() || cur.is_null() {
1620 return -1;
1621 }
1622 crate::xml::tree::xmlNodeDump(buf, doc, cur, level, format)
1623}
1624
1625#[no_mangle]
1633pub unsafe extern "C" fn xmlDocDump(fp: *mut c_void, doc: *mut _xmlDoc) -> c_int {
1634 if fp.is_null() || doc.is_null() {
1635 return -1;
1636 }
1637 crate::xml::tree::xmlDocDump(fp, doc)
1638}
1639
1640#[no_mangle]
1648pub unsafe extern "C" fn xmlDocDumpFormatMemory(
1649 doc: *mut _xmlDoc,
1650 mem: *mut *mut xmlChar,
1651 size: *mut c_int,
1652 format: c_int,
1653) {
1654 if doc.is_null() || mem.is_null() || size.is_null() {
1655 return;
1656 }
1657 crate::xml::tree::xmlDocDumpFormatMemory(doc, mem, size, format)
1658}
1659
1660#[no_mangle]
1668pub unsafe extern "C" fn xmlDocDumpMemory(
1669 doc: *mut _xmlDoc,
1670 mem: *mut *mut xmlChar,
1671 size: *mut c_int,
1672) {
1673 if doc.is_null() || mem.is_null() || size.is_null() {
1674 return;
1675 }
1676 crate::xml::tree::xmlDocDumpMemory(doc, mem, size)
1677}
1678
1679#[no_mangle]
1687pub unsafe extern "C" fn xmlSaveFile(filename: *const c_char, cur: *mut _xmlDoc) -> c_int {
1688 if filename.is_null() || cur.is_null() {
1689 return -1;
1690 }
1691 crate::xml::tree::xmlSaveFile(filename, cur)
1692}
1693
1694#[no_mangle]
1702pub unsafe extern "C" fn xmlSaveFileEnc(
1703 filename: *const c_char,
1704 cur: *mut _xmlDoc,
1705 encoding: *const c_char,
1706) -> c_int {
1707 if filename.is_null() || cur.is_null() {
1708 return -1;
1709 }
1710 crate::xml::tree::xmlSaveFileEnc(filename, cur, encoding)
1711}
1712
1713#[no_mangle]
1721pub unsafe extern "C" fn xmlSaveFormatFile(
1722 filename: *const c_char,
1723 cur: *mut _xmlDoc,
1724 format: c_int,
1725) -> c_int {
1726 if filename.is_null() || cur.is_null() {
1727 return -1;
1728 }
1729 crate::xml::tree::xmlSaveFormatFile(filename, cur, format)
1730}
1731
1732#[no_mangle]
1740pub unsafe extern "C" fn xmlSaveFormatFileEnc(
1741 filename: *const c_char,
1742 cur: *mut _xmlDoc,
1743 encoding: *const c_char,
1744 format: c_int,
1745) -> c_int {
1746 if filename.is_null() || cur.is_null() {
1747 return -1;
1748 }
1749 crate::xml::tree::xmlSaveFormatFileEnc(filename, cur, encoding, format)
1750}
1751
1752#[no_mangle]
1767pub unsafe extern "C" fn xmlReadDoc(
1768 cur: *const xmlChar,
1769 URL: *const c_char,
1770 encoding: *const c_char,
1771 options: c_int,
1772) -> *mut _xmlDoc {
1773 if cur.is_null() {
1775 return ptr::null_mut();
1776 }
1777 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1778 if ctxt.is_null() {
1779 return ptr::null_mut();
1780 }
1781 let len = crate::xml::string::xml_strlen(cur);
1782 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
1783 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1784 (*ctxt).options = options;
1785 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1786 let doc = (*ctxt).myDoc;
1787 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1788 return doc;
1789 }
1790 let doc = (*ctxt).myDoc;
1791 if !doc.is_null() {
1792 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1793 }
1794 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1795 doc
1796}
1797
1798#[no_mangle]
1806pub unsafe extern "C" fn xmlReadFile(
1807 URL: *const c_char,
1808 encoding: *const c_char,
1809 options: c_int,
1810) -> *mut _xmlDoc {
1811 if URL.is_null() {
1813 return ptr::null_mut();
1814 }
1815 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1816 if ctxt.is_null() {
1817 return ptr::null_mut();
1818 }
1819 let input = match crate::xml::parser::helpers::input_from_file(URL) {
1820 Ok(input) => input,
1821 Err(_) => {
1822 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1823 return ptr::null_mut();
1824 }
1825 };
1826 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1827 (*ctxt).options = options;
1828 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1829 let doc = (*ctxt).myDoc;
1830 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1831 return doc;
1832 }
1833 let doc = (*ctxt).myDoc;
1834 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1835 doc
1836}
1837
1838#[no_mangle]
1847pub unsafe extern "C" fn xmlReadMemory(
1848 buffer: *const c_char,
1849 size: c_int,
1850 URL: *const c_char,
1851 encoding: *const c_char,
1852 options: c_int,
1853) -> *mut _xmlDoc {
1854 if buffer.is_null() || size <= 0 {
1856 return ptr::null_mut();
1857 }
1858 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1859 if ctxt.is_null() {
1860 return ptr::null_mut();
1861 }
1862 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
1863 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1864 (*ctxt).options = options;
1865 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1866 let doc = (*ctxt).myDoc;
1867 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1868 return doc;
1869 }
1870 let doc = (*ctxt).myDoc;
1871 if !doc.is_null() && !URL.is_null() {
1872 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1873 }
1874 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1875 doc
1876}
1877
1878#[no_mangle]
1884pub unsafe extern "C" fn xmlLoadCatalogs(catalogs: *const c_char) {
1885 if !catalogs.is_null() {
1886 crate::xml::catalog::load_catalog(catalogs);
1887 }
1888}
1889
1890#[no_mangle]
1896pub unsafe extern "C" fn xmlLoadCatalog(catalogs: *const c_char) -> *mut c_void {
1897 crate::xml::catalog::load_catalog(catalogs)
1898}
1899
1900#[no_mangle]
1908pub unsafe extern "C" fn xmlReadFd(
1909 fd: c_int,
1910 URL: *const c_char,
1911 encoding: *const c_char,
1912 options: c_int,
1913) -> *mut _xmlDoc {
1914 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1916 if ctxt.is_null() {
1917 return ptr::null_mut();
1918 }
1919 let mut buf = Vec::new();
1921 let mut tmp = [0u8; 4096];
1922 loop {
1923 let n = libc::read(fd, tmp.as_mut_ptr() as *mut c_void, tmp.len());
1924 if n <= 0 {
1925 break;
1926 }
1927 buf.extend_from_slice(&tmp[..n as usize]);
1928 }
1929 let input = crate::xml::parser::helpers::input_from_memory(
1930 buf.as_ptr() as *const c_char,
1931 buf.len() as c_int,
1932 );
1933 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1934 (*ctxt).options = options;
1935 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1936 let doc = (*ctxt).myDoc;
1937 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1938 return doc;
1939 }
1940 let doc = (*ctxt).myDoc;
1941 if !doc.is_null() && !URL.is_null() {
1942 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1943 }
1944 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1945 doc
1946}
1947
1948#[no_mangle]
1957pub unsafe extern "C" fn xmlReadIO(
1958 ioread: Option<xmlInputReadCallback>,
1959 ioclose: Option<xmlInputCloseCallback>,
1960 ioctx: *mut c_void,
1961 URL: *const c_char,
1962 encoding: *const c_char,
1963 options: c_int,
1964) -> *mut _xmlDoc {
1965 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1967 if ctxt.is_null() {
1968 return ptr::null_mut();
1969 }
1970 let input = crate::xml::parser::helpers::input_from_io(ioread, ioclose, ioctx);
1971 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1972 (*ctxt).options = options;
1973 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1974 let doc = (*ctxt).myDoc;
1975 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1976 return doc;
1977 }
1978 let doc = (*ctxt).myDoc;
1979 if !doc.is_null() && !URL.is_null() {
1980 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1981 }
1982 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1983 doc
1984}
1985
1986#[no_mangle]
1994pub unsafe extern "C" fn xmlSAXParseDoc(
1995 sax: *mut _xmlSAXHandler,
1996 cur: *const xmlChar,
1997 recovery: c_int,
1998) -> *mut _xmlDoc {
1999 if cur.is_null() {
2001 return ptr::null_mut();
2002 }
2003 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2004 if ctxt.is_null() {
2005 return ptr::null_mut();
2006 }
2007 if !sax.is_null() {
2008 (*ctxt).sax = sax;
2009 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2010 }
2011 if recovery != 0 {
2012 (*ctxt).recovery = 1;
2013 (*ctxt).options |= 1; }
2015 let len = crate::xml::string::xml_strlen(cur);
2016 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
2017 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2018 crate::xml::parser::helpers::parse_document(ctxt);
2019 let doc = (*ctxt).myDoc;
2020 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2021 doc
2022}
2023
2024#[no_mangle]
2032pub unsafe extern "C" fn xmlSAXParseFile(
2033 sax: *mut _xmlSAXHandler,
2034 filename: *const c_char,
2035 recovery: c_int,
2036) -> *mut _xmlDoc {
2037 if filename.is_null() {
2039 return ptr::null_mut();
2040 }
2041 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2042 if ctxt.is_null() {
2043 return ptr::null_mut();
2044 }
2045 if !sax.is_null() {
2046 (*ctxt).sax = sax;
2047 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2048 }
2049 if recovery != 0 {
2050 (*ctxt).recovery = 1;
2051 (*ctxt).options |= 1;
2052 }
2053 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2054 Ok(input) => input,
2055 Err(_) => {
2056 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2057 return ptr::null_mut();
2058 }
2059 };
2060 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2061 crate::xml::parser::helpers::parse_document(ctxt);
2062 let doc = (*ctxt).myDoc;
2063 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2064 doc
2065}
2066
2067#[no_mangle]
2076pub unsafe extern "C" fn xmlSAXParseMemory(
2077 sax: *mut _xmlSAXHandler,
2078 buffer: *const c_char,
2079 size: c_int,
2080 recovery: c_int,
2081) -> *mut _xmlDoc {
2082 if buffer.is_null() || size <= 0 {
2084 return ptr::null_mut();
2085 }
2086 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2087 if ctxt.is_null() {
2088 return ptr::null_mut();
2089 }
2090 if !sax.is_null() {
2091 (*ctxt).sax = sax;
2092 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2093 }
2094 if recovery != 0 {
2095 (*ctxt).recovery = 1;
2096 (*ctxt).options |= 1;
2097 }
2098 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
2099 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2100 crate::xml::parser::helpers::parse_document(ctxt);
2101 let doc = (*ctxt).myDoc;
2102 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2103 doc
2104}
2105
2106#[no_mangle]
2115pub unsafe extern "C" fn xmlSAXUserParseFile(
2116 sax: *mut _xmlSAXHandler,
2117 user_data: *mut c_void,
2118 filename: *const c_char,
2119) -> c_int {
2120 if filename.is_null() {
2122 return -1;
2123 }
2124 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2125 if ctxt.is_null() {
2126 return -1;
2127 }
2128 if !sax.is_null() {
2129 (*ctxt).sax = sax;
2130 }
2131 (*ctxt).userData = if !user_data.is_null() {
2132 user_data
2133 } else {
2134 ctxt as *mut c_void
2135 };
2136 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2137 Ok(input) => input,
2138 Err(_) => {
2139 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2140 return -1;
2141 }
2142 };
2143 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2144 let ret = crate::xml::parser::helpers::parse_document(ctxt);
2145 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2146 ret
2147}
2148
2149#[no_mangle]
2158pub unsafe extern "C" fn xmlSAXUserParseMemory(
2159 sax: *mut _xmlSAXHandler,
2160 user_data: *mut c_void,
2161 buffer: *const c_char,
2162 size: c_int,
2163) -> c_int {
2164 if buffer.is_null() || size <= 0 {
2166 return -1;
2167 }
2168 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2169 if ctxt.is_null() {
2170 return -1;
2171 }
2172 if !sax.is_null() {
2173 (*ctxt).sax = sax;
2174 }
2175 (*ctxt).userData = if !user_data.is_null() {
2176 user_data
2177 } else {
2178 ctxt as *mut c_void
2179 };
2180 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
2181 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2182 let ret = crate::xml::parser::helpers::parse_document(ctxt);
2183 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2184 ret
2185}
2186
2187#[no_mangle]
2195pub unsafe extern "C" fn xmlParseDoc(cur: *const xmlChar) -> *mut _xmlDoc {
2196 if cur.is_null() {
2198 return ptr::null_mut();
2199 }
2200 xmlReadDoc(cur, ptr::null(), ptr::null(), 0)
2201}
2202
2203#[no_mangle]
2211pub unsafe extern "C" fn xmlParseFile(filename: *const c_char) -> *mut _xmlDoc {
2212 if filename.is_null() {
2214 return ptr::null_mut();
2215 }
2216 xmlReadFile(filename, ptr::null(), 0)
2217}
2218
2219#[no_mangle]
2227pub unsafe extern "C" fn xmlParseMemory(buffer: *const c_char, size: c_int) -> *mut _xmlDoc {
2228 if buffer.is_null() || size <= 0 {
2230 return ptr::null_mut();
2231 }
2232 xmlReadMemory(buffer, size, ptr::null(), ptr::null(), 0)
2233}
2234
2235#[no_mangle]
2243pub unsafe extern "C" fn xmlCreateFileParserCtxt(filename: *const c_char) -> *mut _xmlParserCtxt {
2244 if filename.is_null() {
2246 return ptr::null_mut();
2247 }
2248 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2249 if ctxt.is_null() {
2250 return ptr::null_mut();
2251 }
2252 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2253 Ok(input) => input,
2254 Err(_) => {
2255 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2256 return ptr::null_mut();
2257 }
2258 };
2259 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2260 ctxt
2261}
2262
2263#[no_mangle]
2271pub unsafe extern "C" fn xmlCreateDocParserCtxt(cur: *const xmlChar) -> *mut _xmlParserCtxt {
2272 if cur.is_null() {
2274 return ptr::null_mut();
2275 }
2276 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2277 if ctxt.is_null() {
2278 return ptr::null_mut();
2279 }
2280 let len = crate::xml::string::xml_strlen(cur);
2281 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
2282 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2283 ctxt
2284}
2285
2286#[no_mangle]
2294pub unsafe extern "C" fn xmlParseDocument(ctxt: *mut _xmlParserCtxt) -> c_int {
2295 if ctxt.is_null() {
2297 return -1;
2298 }
2299 crate::xml::parser::helpers::parse_document(ctxt)
2300}
2301
2302#[no_mangle]
2310pub unsafe extern "C" fn xmlFreeParserCtxt(ctxt: *mut _xmlParserCtxt) {
2311 if ctxt.is_null() {
2312 return;
2313 }
2314 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2315}
2316
2317#[no_mangle]
2325pub unsafe extern "C" fn xmlCtxtUseOptions(ctxt: *mut _xmlParserCtxt, options: c_int) -> c_int {
2326 if ctxt.is_null() {
2327 return -1;
2328 }
2329 unsafe {
2331 (*ctxt).options = options;
2332 }
2333 0
2334}
2335
2336#[no_mangle]
2345pub unsafe extern "C" fn xmlParseChunk(
2346 ctxt: *mut _xmlParserCtxt,
2347 chunk: *const c_char,
2348 size: c_int,
2349 terminate: c_int,
2350) -> c_int {
2351 if ctxt.is_null() {
2354 return -1;
2355 }
2356 crate::xml::parser::helpers::parse_chunk(ctxt, chunk, size, terminate)
2357}
2358
2359#[no_mangle]
2367pub unsafe extern "C" fn xmlParserInputBufferCreateMem(
2368 buffer: *const c_char,
2369 size: c_int,
2370 enc: c_int,
2371) -> *mut _xmlParserInputBuffer {
2372 if buffer.is_null() || size <= 0 {
2374 return ptr::null_mut();
2375 }
2376 crate::xml::parser::helpers::alloc_parser_input_buffer()
2377}
2378
2379#[no_mangle]
2387pub unsafe extern "C" fn xmlParserInputBufferCreateFilename(
2388 URI: *const c_char,
2389 enc: c_int,
2390) -> *mut _xmlParserInputBuffer {
2391 if URI.is_null() {
2393 return ptr::null_mut();
2394 }
2395 crate::xml::parser::helpers::alloc_parser_input_buffer()
2396}
2397
2398#[no_mangle]
2408pub unsafe extern "C" fn xmlParserInputBufferCreateIO(
2409 ioread: Option<xmlInputReadCallback>,
2410 ioclose: Option<xmlInputCloseCallback>,
2411 ioctx: *mut c_void,
2412 enc: c_int,
2413) -> *mut _xmlParserInputBuffer {
2414 let buf = crate::xml::parser::helpers::alloc_parser_input_buffer();
2416 if !buf.is_null() {
2417 (*buf).readcallback = ioread;
2418 (*buf).closecallback = ioclose;
2419 (*buf).context = ioctx;
2420 }
2421 buf
2422}
2423
2424#[no_mangle]
2432pub unsafe extern "C" fn xmlFreeParserInputBuffer(buf: *mut _xmlParserInputBuffer) {
2433 if buf.is_null() {
2434 return;
2435 }
2436 crate::xml::parser::helpers::free_parser_input_buffer(buf);
2437}
2438
2439#[no_mangle]
2447pub unsafe extern "C" fn xmlNewInputFromFile(
2448 ctxt: *mut _xmlParserCtxt,
2449 filename: *const c_char,
2450) -> *mut _xmlParserInput {
2451 if filename.is_null() {
2456 return ptr::null_mut();
2457 }
2458 crate::xml::parser::helpers::alloc_parser_input_buffer() as *mut _xmlParserInput
2459}
2460
2461#[no_mangle]
2469pub unsafe extern "C" fn xmlFreeInputStream(input: *mut _xmlParserInput) {
2470 if input.is_null() {
2471 return;
2472 }
2473 crate::xml::parser::helpers::free_parser_input(input);
2474}
2475
2476#[no_mangle]
2490pub unsafe extern "C" fn xmlOutputBufferCreateFilename(
2491 URI: *const c_char,
2492 encoder: *mut c_void,
2493 compression: c_int,
2494) -> *mut _xmlOutputBuffer {
2495 let _ = compression;
2496 if URI.is_null() {
2497 return ptr::null_mut();
2498 }
2499 crate::xml::io::output_buffer_create_filename(
2500 URI,
2501 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2502 0,
2503 )
2504}
2505
2506#[no_mangle]
2515pub unsafe extern "C" fn xmlOutputBufferCreateFd(
2516 fd: c_int,
2517 encoder: *mut c_void,
2518) -> *mut _xmlOutputBuffer {
2519 if fd < 0 {
2520 return ptr::null_mut();
2521 }
2522 crate::xml::io::output_buffer_create_fd(
2523 fd,
2524 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2525 )
2526}
2527
2528#[no_mangle]
2538pub unsafe extern "C" fn xmlOutputBufferCreateIO(
2539 iowrite: Option<xmlOutputWriteCallback>,
2540 ioclose: Option<xmlOutputCloseCallback>,
2541 ioctx: *mut c_void,
2542 encoder: *mut c_void,
2543) -> *mut _xmlOutputBuffer {
2544 crate::xml::io::output_buffer_create_io(
2545 iowrite,
2546 ioclose,
2547 ioctx,
2548 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2549 )
2550}
2551
2552#[no_mangle]
2560pub unsafe extern "C" fn xmlOutputBufferClose(out: *mut _xmlOutputBuffer) -> c_int {
2561 if out.is_null() {
2562 return -1;
2563 }
2564 crate::xml::io::output_buffer_close(out)
2565}
2566
2567#[no_mangle]
2575pub unsafe extern "C" fn xmlOutputBufferFlush(out: *mut _xmlOutputBuffer) -> c_int {
2576 if out.is_null() {
2577 return -1;
2578 }
2579 crate::xml::io::output_buffer_flush(out)
2580}
2581
2582#[no_mangle]
2590pub unsafe extern "C" fn xmlOutputBufferWrite(
2591 out: *mut _xmlOutputBuffer,
2592 len: c_int,
2593 data: *const c_char,
2594) -> c_int {
2595 if out.is_null() || data.is_null() || len <= 0 {
2596 return -1;
2597 }
2598 crate::xml::io::output_buffer_write(out, len, data)
2599}
2600
2601#[no_mangle]
2609pub unsafe extern "C" fn xmlOutputBufferWriteString(
2610 out: *mut _xmlOutputBuffer,
2611 str: *const c_char,
2612) -> c_int {
2613 if str.is_null() {
2614 return 0;
2615 }
2616 unsafe { xmlOutputBufferWrite(out, xmlStrlen(str as *const xmlChar), str) }
2617}
2618
2619#[no_mangle]
2631pub extern "C" fn xmlDictCreate() -> *mut c_void {
2632 ptr::null_mut()
2634}
2635
2636#[no_mangle]
2644pub extern "C" fn xmlDictCreateSub(_sub: *mut c_void) -> *mut c_void {
2645 ptr::null_mut()
2647}
2648
2649#[no_mangle]
2661pub unsafe extern "C" fn xmlDictLookup(
2662 dict: *mut c_void,
2663 name: *const xmlChar,
2664 len: c_int,
2665) -> *const xmlChar {
2666 name
2668}
2669
2670#[no_mangle]
2678pub unsafe extern "C" fn xmlDictExists(
2679 dict: *mut c_void,
2680 name: *const xmlChar,
2681 len: c_int,
2682) -> *const xmlChar {
2683 ptr::null()
2685}
2686
2687#[no_mangle]
2695pub extern "C" fn xmlDictSize(dict: *const c_void) -> c_uint {
2696 0
2698}
2699
2700#[no_mangle]
2708pub extern "C" fn xmlDictFree(_dict: *mut c_void) {
2709 }
2711
2712#[no_mangle]
2720pub extern "C" fn xmlDictSetLimit(_dict: *mut c_void, _limit: c_uint) -> c_uint {
2721 0
2723}
2724
2725#[no_mangle]
2733pub extern "C" fn xmlDictGetUsage(_dict: *const c_void) -> c_uint {
2734 0
2736}
2737
2738#[no_mangle]
2750pub extern "C" fn xmlHashCreate(_size: c_int) -> *mut c_void {
2751 ptr::null_mut()
2753}
2754
2755#[no_mangle]
2763pub extern "C" fn xmlHashCreateDict(_size: c_int, _dict: *mut c_void) -> *mut c_void {
2764 ptr::null_mut()
2766}
2767
2768#[no_mangle]
2776pub extern "C" fn xmlHashFree(
2777 _table: *mut c_void,
2778 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2779) {
2780 }
2782
2783#[no_mangle]
2791pub unsafe extern "C" fn xmlHashAddEntry(
2792 _table: *mut c_void,
2793 _name: *const xmlChar,
2794 _userdata: *mut c_void,
2795) -> c_int {
2796 0
2798}
2799
2800#[no_mangle]
2809pub unsafe extern "C" fn xmlHashAddEntry2(
2810 _table: *mut c_void,
2811 _name: *const xmlChar,
2812 _name2: *const xmlChar,
2813 _userdata: *mut c_void,
2814) -> c_int {
2815 0
2817}
2818
2819#[no_mangle]
2828pub unsafe extern "C" fn xmlHashAddEntry3(
2829 _table: *mut c_void,
2830 _name: *const xmlChar,
2831 _name2: *const xmlChar,
2832 _name3: *const xmlChar,
2833 _userdata: *mut c_void,
2834) -> c_int {
2835 0
2837}
2838
2839#[no_mangle]
2848pub unsafe extern "C" fn xmlHashUpdateEntry(
2849 _table: *mut c_void,
2850 _name: *const xmlChar,
2851 _userdata: *mut c_void,
2852 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2853) -> c_int {
2854 0
2856}
2857
2858#[no_mangle]
2860pub unsafe extern "C" fn xmlHashUpdateEntry2(
2861 _table: *mut c_void,
2862 _name: *const xmlChar,
2863 _name2: *const xmlChar,
2864 _userdata: *mut c_void,
2865 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2866) -> c_int {
2867 0
2869}
2870
2871#[no_mangle]
2873pub unsafe extern "C" fn xmlHashUpdateEntry3(
2874 _table: *mut c_void,
2875 _name: *const xmlChar,
2876 _name2: *const xmlChar,
2877 _name3: *const xmlChar,
2878 _userdata: *mut c_void,
2879 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2880) -> c_int {
2881 0
2883}
2884
2885#[no_mangle]
2893pub unsafe extern "C" fn xmlHashLookup(_table: *mut c_void, _name: *const xmlChar) -> *mut c_void {
2894 ptr::null_mut()
2896}
2897
2898#[no_mangle]
2900pub unsafe extern "C" fn xmlHashLookup2(
2901 _table: *mut c_void,
2902 _name: *const xmlChar,
2903 _name2: *const xmlChar,
2904) -> *mut c_void {
2905 ptr::null_mut()
2907}
2908
2909#[no_mangle]
2911pub unsafe extern "C" fn xmlHashLookup3(
2912 _table: *mut c_void,
2913 _name: *const xmlChar,
2914 _name2: *const xmlChar,
2915 _name3: *const xmlChar,
2916) -> *mut c_void {
2917 ptr::null_mut()
2919}
2920
2921#[no_mangle]
2929pub extern "C" fn xmlHashSize(_table: *mut c_void) -> c_int {
2930 0
2932}
2933
2934#[no_mangle]
2943pub unsafe extern "C" fn xmlHashRemoveEntry(
2944 _table: *mut c_void,
2945 _name: *const xmlChar,
2946 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2947) -> c_int {
2948 0
2950}
2951
2952#[no_mangle]
2954pub unsafe extern "C" fn xmlHashRemoveEntry2(
2955 _table: *mut c_void,
2956 _name: *const xmlChar,
2957 _name2: *const xmlChar,
2958 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2959) -> c_int {
2960 0
2962}
2963
2964#[no_mangle]
2966pub unsafe extern "C" fn xmlHashRemoveEntry3(
2967 _table: *mut c_void,
2968 _name: *const xmlChar,
2969 _name2: *const xmlChar,
2970 _name3: *const xmlChar,
2971 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2972) -> c_int {
2973 0
2975}
2976
2977#[no_mangle]
2985pub extern "C" fn xmlHashScan(
2986 _table: *mut c_void,
2987 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void)>,
2988 _data: *mut c_void,
2989) {
2990 }
2992
2993#[no_mangle]
2995pub extern "C" fn xmlHashScanFull(
2996 _table: *mut c_void,
2997 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void, *mut c_void)>,
2998 _data: *mut c_void,
2999) {
3000 }
3002
3003#[no_mangle]
3011pub extern "C" fn xmlHashCopy(
3012 _table: *mut c_void,
3013 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar) -> *mut c_void>,
3014) -> *mut c_void {
3015 ptr::null_mut()
3017}
3018
3019#[no_mangle]
3032pub extern "C" fn xmlListCreate(
3033 _deallocator: Option<unsafe extern "C" fn(*mut c_void)>,
3034 _compare: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
3035) -> *mut c_void {
3036 ptr::null_mut()
3038}
3039
3040#[no_mangle]
3048pub extern "C" fn xmlListDelete(_list: *mut c_void) {
3049 }
3051
3052#[no_mangle]
3060pub extern "C" fn xmlListSearch(_list: *mut c_void, _data: *mut c_void) -> *mut c_void {
3061 ptr::null_mut()
3063}
3064
3065#[no_mangle]
3073pub extern "C" fn xmlListWalk(
3074 _list: *mut c_void,
3075 _walker: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
3076 _data: *mut c_void,
3077) {
3078 }
3080
3081#[no_mangle]
3089pub extern "C" fn xmlListPushBack(_list: *mut c_void, _data: *mut c_void) -> c_int {
3090 0
3092}
3093
3094#[no_mangle]
3102pub extern "C" fn xmlListPushFront(_list: *mut c_void, _data: *mut c_void) -> c_int {
3103 0
3105}
3106
3107#[no_mangle]
3109pub extern "C" fn xmlListPopBack(_list: *mut c_void) {
3110 }
3112
3113#[no_mangle]
3115pub extern "C" fn xmlListPopFront(_list: *mut c_void) {
3116 }
3118
3119#[no_mangle]
3127pub extern "C" fn xmlListInsert(_list: *mut c_void, _data: *mut c_void) -> c_int {
3128 0
3130}
3131
3132#[no_mangle]
3134pub extern "C" fn xmlListAppend(_list: *mut c_void, _data: *mut c_void) -> c_int {
3135 0
3137}
3138
3139#[no_mangle]
3141pub extern "C" fn xmlListRemoveFirst(_list: *mut c_void, _data: *mut c_void) -> c_int {
3142 0
3144}
3145
3146#[no_mangle]
3148pub extern "C" fn xmlListRemoveLast(_list: *mut c_void, _data: *mut c_void) -> c_int {
3149 0
3151}
3152
3153#[no_mangle]
3155pub extern "C" fn xmlListRemoveAll(_list: *mut c_void, _data: *mut c_void) -> c_int {
3156 0
3158}
3159
3160#[no_mangle]
3162pub extern "C" fn xmlListClear(_list: *mut c_void) {
3163 }
3165
3166#[no_mangle]
3174pub extern "C" fn xmlListEmpty(_list: *mut c_void) -> c_int {
3175 1
3177}
3178
3179#[no_mangle]
3187pub extern "C" fn xmlListFront(_list: *mut c_void) -> *mut c_void {
3188 ptr::null_mut()
3190}
3191
3192#[no_mangle]
3200pub extern "C" fn xmlListBack(_list: *mut c_void) -> *mut c_void {
3201 ptr::null_mut()
3203}
3204
3205#[no_mangle]
3213pub extern "C" fn xmlListSize(_list: *mut c_void) -> c_int {
3214 0
3216}
3217
3218#[no_mangle]
3220pub extern "C" fn xmlListSort(_list: *mut c_void) {
3221 }
3223
3224#[no_mangle]
3226pub extern "C" fn xmlListReverse(_list: *mut c_void) {
3227 }
3229
3230#[no_mangle]
3232pub extern "C" fn xmlListReverseSplice(_list: *mut c_void, _list2: *mut c_void) {
3233 }
3235
3236#[no_mangle]
3238pub extern "C" fn xmlListMerge(_list: *mut c_void, _list2: *mut c_void) {
3239 }
3241
3242#[no_mangle]
3254pub extern "C" fn xmlBufferCreate() -> *mut _xmlBuffer {
3255 crate::xml::io::buf_create(-1)
3256}
3257
3258#[no_mangle]
3266pub extern "C" fn xmlBufferCreateSize(size: usize) -> *mut _xmlBuffer {
3267 crate::xml::io::buf_create(size as c_int)
3268}
3269
3270#[no_mangle]
3278pub extern "C" fn xmlBufferCreateStatic(mem: *mut c_void, size: usize) -> *mut _xmlBuffer {
3279 if mem.is_null() || size == 0 {
3280 return ptr::null_mut();
3281 }
3282 crate::xml::io::buf_create_static(mem as *const xmlChar, size as c_int)
3283}
3284
3285#[no_mangle]
3293pub extern "C" fn xmlBufferFree(buf: *mut _xmlBuffer) {
3294 crate::xml::io::buf_free(buf)
3295}
3296
3297#[no_mangle]
3305pub extern "C" fn xmlBufferEmpty(buf: *mut _xmlBuffer) {
3306 if buf.is_null() {
3307 return;
3308 }
3309 unsafe {
3310 if !(*buf).content.is_null() {
3311 *(*buf).content = 0;
3312 }
3313 (*buf).use_ = 0;
3314 }
3315}
3316
3317#[no_mangle]
3325pub extern "C" fn xmlBufferContent(buf: *const _xmlBuffer) -> *mut xmlChar {
3326 crate::xml::io::buf_content(buf as *mut _xmlBuffer)
3327}
3328
3329#[no_mangle]
3337pub extern "C" fn xmlBufferLength(buf: *const _xmlBuffer) -> c_int {
3338 crate::xml::io::buf_length(buf as *mut _xmlBuffer)
3339}
3340
3341#[no_mangle]
3349pub unsafe extern "C" fn xmlBufferAdd(
3350 buf: *mut _xmlBuffer,
3351 str: *const xmlChar,
3352 len: c_int,
3353) -> c_int {
3354 crate::xml::io::buf_add(buf, str, len)
3355}
3356
3357#[no_mangle]
3365pub unsafe extern "C" fn xmlBufferAddHead(
3366 buf: *mut _xmlBuffer,
3367 str: *const xmlChar,
3368 len: c_int,
3369) -> c_int {
3370 crate::xml::io::buf_add_head(buf, str, len)
3371}
3372
3373#[no_mangle]
3381pub unsafe extern "C" fn xmlBufferCat(buf: *mut _xmlBuffer, str: *const xmlChar) -> c_int {
3382 if str.is_null() {
3383 return -1;
3384 }
3385 let len = crate::xml::string::xml_strlen(str) as c_int;
3386 crate::xml::io::buf_add(buf, str, len)
3387}
3388
3389#[no_mangle]
3398pub extern "C" fn xmlBufferSetAllocationScheme(buf: *mut _xmlBuffer, scheme: c_int) {
3399 if buf.is_null() {
3400 return;
3401 }
3402 unsafe {
3403 (*buf).alloc = scheme;
3404 }
3405}
3406
3407#[no_mangle]
3415pub extern "C" fn xmlBufferShrink(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3416 if buf.is_null() || len <= 0 {
3417 return 0;
3418 }
3419 unsafe {
3420 let b = &mut *buf;
3421 let shrink_len = (len as c_uint).min(b.use_);
3422 if shrink_len > 0 {
3423 let remaining = b.use_ - shrink_len;
3424 if remaining > 0 {
3425 core::ptr::copy(
3426 b.content.add(shrink_len as usize),
3427 b.content,
3428 remaining as usize,
3429 );
3430 }
3431 *b.content.add(remaining as usize) = 0;
3432 b.use_ = remaining;
3433 }
3434 }
3435 len
3436}
3437
3438#[no_mangle]
3446pub extern "C" fn xmlBufferGrow(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3447 if buf.is_null() || len <= 0 {
3448 return 0;
3449 }
3450 let cur_use = unsafe { (*buf).use_ };
3451 let new_size = cur_use + len as c_uint + 1;
3452 crate::xml::io::buf_grow(buf, new_size)
3453}
3454
3455#[no_mangle]
3463pub extern "C" fn xmlBufferReserve(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3464 xmlBufferGrow(buf, len)
3465}
3466
3467#[no_mangle]
3475pub extern "C" fn xmlBufferDetach(buf: *mut _xmlBuffer) -> *mut xmlChar {
3476 if buf.is_null() {
3477 return ptr::null_mut();
3478 }
3479 unsafe {
3480 let content = (*buf).content;
3481 (*buf).content = ptr::null_mut();
3482 (*buf).use_ = 0;
3483 (*buf).size = 0;
3484 content
3485 }
3486}
3487
3488#[no_mangle]
3500pub extern "C" fn xmlGetCharEncoding(name: *const c_char) -> c_int {
3501 if name.is_null() {
3502 return 0; }
3504 let name_bytes = unsafe {
3505 let len = libc::strlen(name);
3506 core::slice::from_raw_parts(name as *const u8, len)
3507 };
3508 crate::xml::encoding::encoding_from_name(name_bytes) as c_int
3509}
3510
3511#[no_mangle]
3519pub extern "C" fn xmlFindCharEncodingHandler(name: *const c_char) -> *mut c_void {
3520 if name.is_null() {
3521 return ptr::null_mut();
3522 }
3523 crate::xml::encoding::find_encoding_handler(name as *const xmlChar) as *mut c_void
3524}
3525
3526#[no_mangle]
3534pub extern "C" fn xmlCharEncCloseFunc(handler: *mut c_void) -> c_int {
3535 if handler.is_null() {
3536 return -1;
3537 }
3538 unsafe {
3540 let h = handler as *mut crate::abi::structs::_xmlCharEncodingHandler;
3541 if !(*h).name.is_null() {
3542 crate::abi::allocator::xmlFree((*h).name as *mut c_void);
3543 }
3544 crate::abi::allocator::xmlFree(handler);
3545 }
3546 0
3547}
3548
3549#[no_mangle]
3557pub unsafe extern "C" fn xmlCharEncInput(input: *mut _xmlParserInputBuffer, _to: c_int) -> c_int {
3558 if input.is_null() {
3559 return -1;
3560 }
3561 let handler = (*input).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3562 if handler.is_null() {
3563 return -1;
3564 }
3565 let raw = (*input).raw as *mut crate::abi::structs::_xmlBuffer;
3566 let buf = (*input).buffer as *mut crate::abi::structs::_xmlBuffer;
3567 if raw.is_null() || buf.is_null() {
3568 return -1;
3569 }
3570 crate::xml::encoding::char_enc_in(handler, buf, raw)
3571}
3572
3573#[no_mangle]
3581pub unsafe extern "C" fn xmlCharEncOutput(output: *mut _xmlOutputBuffer, _to: c_int) -> c_int {
3582 if output.is_null() {
3583 return -1;
3584 }
3585 let handler = (*output).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3586 if handler.is_null() {
3587 return -1;
3588 }
3589 let buf = (*output).buffer as *mut crate::abi::structs::_xmlBuffer;
3590 let conv = (*output).conv as *mut crate::abi::structs::_xmlBuffer;
3591 if buf.is_null() || conv.is_null() {
3592 return -1;
3593 }
3594 crate::xml::encoding::char_enc_out(handler, conv, buf)
3595}
3596
3597#[no_mangle]
3609pub unsafe extern "C" fn xmlParseURI(str: *const c_char) -> *mut c_void {
3610 crate::xml::uri::xmlParseURI(str)
3611}
3612
3613#[no_mangle]
3621pub unsafe extern "C" fn xmlParseURIRaw(str: *const c_char, raw: c_int) -> *mut c_void {
3622 let _ = raw;
3623 crate::xml::uri::xmlParseURI(str)
3624}
3625
3626#[no_mangle]
3634pub unsafe extern "C" fn xmlFreeURI(uri: *mut c_void) {
3635 crate::xml::uri::xmlFreeURI(uri)
3636}
3637
3638#[no_mangle]
3646pub extern "C" fn xmlCreateURI() -> *mut c_void {
3647 crate::xml::uri::xmlCreateURI()
3648}
3649
3650#[no_mangle]
3658pub unsafe extern "C" fn xmlSaveUri(uri: *mut c_void) -> *mut xmlChar {
3659 crate::xml::uri::xmlSaveUri(uri)
3660}
3661
3662#[no_mangle]
3670pub unsafe extern "C" fn xmlURIEscapeStr(
3671 str: *const xmlChar,
3672 list: *const xmlChar,
3673) -> *mut xmlChar {
3674 crate::xml::uri::xmlURIEscapeStr(str, list)
3675}
3676
3677#[no_mangle]
3685pub unsafe extern "C" fn xmlURIUnescapeString(
3686 str: *const c_char,
3687 len: c_int,
3688 target: *mut c_char,
3689) -> *mut c_char {
3690 crate::xml::uri::xmlURIUnescapeString(str, len, target)
3691}
3692
3693unsafe fn xpath_to_object(val: XPathValue) -> *mut _xmlXPathObject {
3708 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
3709 if obj.is_null() {
3710 return ptr::null_mut();
3711 }
3712 match val {
3713 XPathValue::NodeSet(ns) => {
3714 (*obj).type_ = xmlXPathObjectType::XPATH_NODESET as c_int;
3715 (*obj).nodesetval = ns.to_raw() as *mut c_void;
3716 }
3717 XPathValue::Boolean(b) => {
3718 (*obj).type_ = xmlXPathObjectType::XPATH_BOOLEAN as c_int;
3719 (*obj).boolval = if b { 1 } else { 0 };
3720 }
3721 XPathValue::Number(n) => {
3722 (*obj).type_ = xmlXPathObjectType::XPATH_NUMBER as c_int;
3723 (*obj).floatval = n;
3724 }
3725 XPathValue::String(s) => {
3726 (*obj).type_ = xmlXPathObjectType::XPATH_STRING as c_int;
3727 let bytes = s.as_bytes();
3728 let len = bytes.len();
3729 let buf = xmlMalloc(len + 1) as *mut xmlChar;
3730 if !buf.is_null() {
3731 ptr::copy_nonoverlapping(bytes.as_ptr(), buf, len);
3732 *buf.add(len) = 0; }
3734 (*obj).stringval = buf;
3735 }
3736 }
3737 obj
3738}
3739
3740unsafe fn object_to_xpathvalue(obj: *mut _xmlXPathObject) -> XPathValue {
3747 let typ = (*obj).type_;
3748 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3749 let ns_ptr = (*obj).nodesetval as *mut _xmlNodeSet;
3750 if ns_ptr.is_null() {
3751 return XPathValue::NodeSet(NodeSet::new());
3752 }
3753 let node_nr = (*ns_ptr).nodeNr;
3754 let node_tab = (*ns_ptr).nodeTab;
3755 let mut ns = NodeSet::new();
3756 if !node_tab.is_null() {
3757 for i in 0..node_nr as isize {
3758 let node = *node_tab.add(i as usize);
3759 ns.push(node);
3760 }
3761 }
3762 XPathValue::NodeSet(ns)
3763 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
3764 XPathValue::Boolean((*obj).boolval != 0)
3765 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
3766 XPathValue::Number((*obj).floatval)
3767 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3768 let s_ptr = (*obj).stringval;
3769 if s_ptr.is_null() {
3770 XPathValue::String(String::new())
3771 } else {
3772 let s = CStr::from_ptr(s_ptr as *const c_char)
3773 .to_string_lossy()
3774 .into_owned();
3775 XPathValue::String(s)
3776 }
3777 } else if typ == xmlXPathObjectType::XPATH_XSLT_TREE as c_int {
3778 let frag_doc = (*obj).nodesetval as *mut _xmlDoc;
3783 if frag_doc.is_null() {
3784 XPathValue::NodeSet(NodeSet::new())
3785 } else {
3786 let mut ns = NodeSet::new();
3787 ns.push(frag_doc as *mut _xmlNode);
3788 XPathValue::NodeSet(ns)
3789 }
3790 } else {
3791 XPathValue::Boolean(false)
3793 }
3794}
3795
3796pub unsafe fn object_to_xpathvalue_pub(obj: *mut _xmlXPathObject) -> XPathValue {
3803 object_to_xpathvalue(obj)
3804}
3805
3806static COMPILED_EXPRS: Lazy<Mutex<HashMap<u64, Box<CompiledExpr>>>> =
3812 Lazy::new(|| Mutex::new(HashMap::new()));
3813static NEXT_COMPILED_KEY: Lazy<Mutex<u64>> = Lazy::new(|| Mutex::new(1));
3814
3815type CXPathFunc = unsafe extern "C" fn(*mut c_void, c_int);
3825
3826#[derive(Clone, Copy, PartialEq, Eq, Hash)]
3829struct SendSyncPtr(*mut c_void);
3830unsafe impl Send for SendSyncPtr {}
3831unsafe impl Sync for SendSyncPtr {}
3832
3833static C_FUNCTIONS: Lazy<Mutex<HashMap<(SendSyncPtr, String), CXPathFunc>>> =
3834 Lazy::new(|| Mutex::new(HashMap::new()));
3835
3836fn c_func_stub(_ctx: &mut XPathContext, _args: &[XPathValue]) -> Result<XPathValue, String> {
3841 Err(
3842 "C extension function cannot be called from Rust evaluator without a parser-context bridge"
3843 .to_string(),
3844 )
3845}
3846
3847#[no_mangle]
3860pub unsafe extern "C" fn xmlXPathNewContext(doc: *mut _xmlDoc) -> *mut _xmlXPathContext {
3861 let ctxt = xmlMallocZero(size_of::<_xmlXPathContext>()) as *mut _xmlXPathContext;
3862 if ctxt.is_null() {
3863 return ptr::null_mut();
3864 }
3865
3866 (*ctxt).doc = doc;
3868 (*ctxt).node = ptr::null_mut();
3869 (*ctxt).contextSize = 1;
3870 (*ctxt).proximityPosition = 1;
3871
3872 let internal = Box::new(XPathContext::new(doc));
3874 (*ctxt).extra = Box::into_raw(internal) as *mut c_void;
3875
3876 ctxt
3877}
3878
3879#[no_mangle]
3887pub unsafe extern "C" fn xmlXPathFreeContext(ctxt: *mut _xmlXPathContext) {
3888 if ctxt.is_null() {
3889 return;
3890 }
3891 if !(*ctxt).extra.is_null() {
3893 let _ = Box::from_raw((*ctxt).extra as *mut XPathContext);
3894 (*ctxt).extra = ptr::null_mut();
3895 }
3896 xmlFree(ctxt as *mut c_void);
3898}
3899
3900#[no_mangle]
3909pub unsafe extern "C" fn xmlXPathEvalExpression(
3910 str_: *const xmlChar,
3911 ctxt: *mut _xmlXPathContext,
3912) -> *mut _xmlXPathObject {
3913 if str_.is_null() || ctxt.is_null() {
3914 return ptr::null_mut();
3915 }
3916 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
3917 Ok(s) => s,
3918 Err(_) => return ptr::null_mut(),
3919 };
3920 let internal = (*ctxt).extra as *mut XPathContext;
3921 if internal.is_null() {
3922 return ptr::null_mut();
3923 }
3924 let internal = &mut *internal;
3925
3926 match crate::xml::xpath::evaluate_str(expr_str, internal) {
3927 Some(val) => xpath_to_object(val),
3928 None => {
3929 if internal.error.is_none() {
3934 internal.set_error("Invalid expression");
3935 }
3936 ptr::null_mut()
3937 }
3938 }
3939}
3940
3941#[no_mangle]
3949pub unsafe extern "C" fn xmlXPathEval(
3950 str_: *const xmlChar,
3951 ctxt: *mut _xmlXPathContext,
3952) -> *mut _xmlXPathObject {
3953 xmlXPathEvalExpression(str_, ctxt)
3954}
3955
3956#[no_mangle]
3967pub unsafe extern "C" fn xmlXPathFreeObject(obj: *mut _xmlXPathObject) {
3968 if obj.is_null() {
3969 return;
3970 }
3971 let typ = (*obj).type_;
3972 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3974 if !(*obj).stringval.is_null() {
3975 xmlFree((*obj).stringval as *mut c_void);
3976 (*obj).stringval = ptr::null_mut();
3977 }
3978 }
3979 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3981 let ns = (*obj).nodesetval as *mut _xmlNodeSet;
3982 if !ns.is_null() {
3983 if !(*ns).nodeTab.is_null() {
3984 xmlFree((*ns).nodeTab as *mut c_void);
3985 }
3986 xmlFree(ns as *mut c_void);
3987 }
3988 (*obj).nodesetval = ptr::null_mut();
3989 }
3990 xmlFree(obj as *mut c_void);
3991}
3992
3993#[no_mangle]
4005pub unsafe extern "C" fn xmlXPathObjectCopy(val: *mut _xmlXPathObject) -> *mut _xmlXPathObject {
4006 if val.is_null() {
4007 return ptr::null_mut();
4008 }
4009 let typ = (*val).type_;
4010 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
4011 if obj.is_null() {
4012 return ptr::null_mut();
4013 }
4014 (*obj).type_ = typ;
4015 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
4016 let src_ns = (*val).nodesetval as *mut _xmlNodeSet;
4017 if !src_ns.is_null() {
4018 let nr = (*src_ns).nodeNr;
4019 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
4020 if ns.is_null() {
4021 xmlFree(obj as *mut c_void);
4022 return ptr::null_mut();
4023 }
4024 (*ns).nodeNr = nr;
4025 (*ns).nodeMax = nr;
4026 if nr > 0 && !(*src_ns).nodeTab.is_null() {
4027 let tab = xmlMalloc((nr as usize) * core::mem::size_of::<*mut _xmlNode>())
4028 as *mut *mut _xmlNode;
4029 if tab.is_null() {
4030 xmlFree(ns as *mut c_void);
4031 xmlFree(obj as *mut c_void);
4032 return ptr::null_mut();
4033 }
4034 ptr::copy_nonoverlapping((*src_ns).nodeTab, tab, nr as usize);
4035 (*ns).nodeTab = tab;
4036 } else {
4037 (*ns).nodeTab = ptr::null_mut();
4038 }
4039 (*obj).nodesetval = ns as *mut c_void;
4040 }
4041 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
4042 (*obj).boolval = (*val).boolval;
4043 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
4044 (*obj).floatval = (*val).floatval;
4045 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
4046 let src = (*val).stringval;
4047 if !src.is_null() {
4048 let len = libc::strlen(src as *const libc::c_char);
4049 let buf = xmlMalloc(len + 1) as *mut xmlChar;
4050 if !buf.is_null() {
4051 ptr::copy_nonoverlapping(src, buf, len);
4052 *buf.add(len) = 0;
4053 }
4054 (*obj).stringval = buf;
4055 }
4056 }
4057 obj
4058}
4059
4060#[no_mangle]
4070pub unsafe extern "C" fn xmlXPathCastToString(val: *mut _xmlXPathObject) -> *mut xmlChar {
4071 if val.is_null() {
4072 return ptr::null_mut();
4073 }
4074 let typ = (*val).type_;
4075 let mut result: Vec<u8> = Vec::new();
4076 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
4077 if !(*val).stringval.is_null() {
4078 let len = libc::strlen((*val).stringval as *const libc::c_char);
4079 result.extend_from_slice(core::slice::from_raw_parts((*val).stringval, len));
4080 }
4081 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
4082 let n = (*val).floatval;
4088 result.extend_from_slice(xml_number_to_string(n).as_bytes());
4089 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
4090 result.extend_from_slice(if (*val).boolval != 0 {
4091 b"true"
4092 } else {
4093 b"false"
4094 });
4095 } else if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
4096 let ns = (*val).nodesetval as *mut _xmlNodeSet;
4099 if !ns.is_null() && (*ns).nodeNr > 0 && !(*ns).nodeTab.is_null() {
4100 let node = *(*ns).nodeTab;
4101 if !node.is_null() {
4102 let content = crate::xml::tree::node_get_content(node);
4103 if !content.is_null() {
4104 let len = libc::strlen(content as *const libc::c_char);
4105 result.extend_from_slice(core::slice::from_raw_parts(content, len));
4106 xmlFree(content as *mut c_void);
4107 }
4108 }
4109 }
4110 }
4111 let buf = xmlMalloc(result.len() + 1) as *mut xmlChar;
4113 if buf.is_null() {
4114 return ptr::null_mut();
4115 }
4116 if !result.is_empty() {
4117 ptr::copy_nonoverlapping(result.as_ptr(), buf, result.len());
4118 }
4119 *buf.add(result.len()) = 0;
4120 buf
4121}
4122
4123pub fn xml_number_to_string(n: f64) -> String {
4127 if n.is_nan() {
4128 return "NaN".to_string();
4129 }
4130 if n.is_infinite() {
4131 return if n > 0.0 {
4132 "Infinity".to_string()
4133 } else {
4134 "-Infinity".to_string()
4135 };
4136 }
4137 if n == 0.0 {
4138 return "0".to_string();
4140 }
4141 if n.fract() == 0.0 && n.abs() < 1e15 {
4143 return format!("{:.0}", n);
4144 }
4145 let mut s = format!("{:.15}", n);
4149 if s.contains('.') {
4151 while s.ends_with('0') {
4152 s.pop();
4153 }
4154 if s.ends_with('.') {
4155 s.pop();
4156 }
4157 }
4158 if s == "-0" {
4159 return "0".to_string();
4160 }
4161 s
4162}
4163
4164#[no_mangle]
4172pub unsafe extern "C" fn xmlXPathCastStringToNumber(val: *const xmlChar) -> f64 {
4173 if val.is_null() {
4174 return f64::NAN;
4175 }
4176 let len = libc::strlen(val as *const libc::c_char);
4177 let bytes = core::slice::from_raw_parts(val, len);
4178 let mut i = 0;
4180 while i < bytes.len() && matches!(bytes[i], b' ' | b'\t' | b'\n' | b'\r') {
4181 i += 1;
4182 }
4183 let s = &bytes[i..];
4184 if s.is_empty() {
4185 return f64::NAN;
4186 }
4187 let (sign, rest) = match s[0] {
4189 b'+' => (1.0f64, &s[1..]),
4190 b'-' => (-1.0f64, &s[1..]),
4191 _ => (1.0f64, s),
4192 };
4193 if rest.is_empty() {
4194 return f64::NAN;
4195 }
4196 let num_str = core::str::from_utf8(rest);
4199 match num_str {
4200 Ok(s) => {
4201 let valid = is_xpath_number(s);
4204 if !valid {
4205 f64::NAN
4206 } else {
4207 s.trim()
4208 .parse::<f64>()
4209 .map(|v| v * sign)
4210 .unwrap_or(f64::NAN)
4211 }
4212 }
4213 Err(_) => f64::NAN,
4214 }
4215}
4216
4217fn is_xpath_number(s: &str) -> bool {
4219 let b = s.as_bytes();
4220 if b.is_empty() {
4221 return false;
4222 }
4223 let mut i = 0;
4224 let mut saw_digit = false;
4225 while i < b.len() && b[i].is_ascii_digit() {
4226 saw_digit = true;
4227 i += 1;
4228 }
4229 if i < b.len() && b[i] == b'.' {
4230 i += 1;
4231 while i < b.len() && b[i].is_ascii_digit() {
4232 saw_digit = true;
4233 i += 1;
4234 }
4235 }
4236 if !saw_digit {
4237 return false;
4238 }
4239 if i < b.len() && (b[i] == b'e' || b[i] == b'E') {
4240 i += 1;
4241 if i < b.len() && (b[i] == b'+' || b[i] == b'-') {
4242 i += 1;
4243 }
4244 let mut saw_exp = false;
4245 while i < b.len() && b[i].is_ascii_digit() {
4246 saw_exp = true;
4247 i += 1;
4248 }
4249 if !saw_exp {
4250 return false;
4251 }
4252 }
4253 i == b.len()
4254}
4255
4256#[no_mangle]
4271pub unsafe extern "C" fn xmlXPathCmpNodes(node1: *mut _xmlNode, node2: *mut _xmlNode) -> c_int {
4272 if node1.is_null() || node2.is_null() {
4273 return 0;
4274 }
4275 if node1 == node2 {
4276 return 0;
4277 }
4278 let mut chain1: Vec<*mut _xmlNode> = Vec::new();
4280 let mut chain2: Vec<*mut _xmlNode> = Vec::new();
4281 let mut n = node1;
4282 while !n.is_null() {
4283 chain1.push(n);
4284 n = (*n).parent as *mut _xmlNode;
4285 }
4286 let mut n = node2;
4287 while !n.is_null() {
4288 chain2.push(n);
4289 n = (*n).parent as *mut _xmlNode;
4290 }
4291 let mut i = chain1.len();
4293 let mut j = chain2.len();
4294 while i > 0 && j > 0 && chain1[i - 1] == chain2[j - 1] {
4295 i -= 1;
4296 j -= 1;
4297 }
4298 if i == 0 && j == 0 {
4299 return 0; }
4301 if i == 0 {
4302 return -1; }
4304 if j == 0 {
4305 return 1; }
4307 let mut a = chain1[i - 1];
4309 let mut b = chain2[j - 1];
4310 while !a.is_null() && !b.is_null() {
4312 let pa = (*a).parent as *mut _xmlNode;
4313 let pb = (*b).parent as *mut _xmlNode;
4314 if pa == pb {
4315 break;
4316 }
4317 a = pa;
4318 b = pb;
4319 }
4320 let parent = (*a).parent as *mut _xmlNode;
4322 let mut child = if parent.is_null() {
4323 ptr::null_mut()
4324 } else {
4325 (*parent).children
4326 };
4327 while !child.is_null() {
4328 if child == a {
4329 return -1;
4330 }
4331 if child == b {
4332 return 1;
4333 }
4334 child = (*child).next;
4335 }
4336 0
4337}
4338
4339#[no_mangle]
4349pub unsafe extern "C" fn xmlXPathNodeSetCreate(val: *mut _xmlNode) -> *mut _xmlNodeSet {
4350 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
4351 if ns.is_null() {
4352 return ptr::null_mut();
4353 }
4354 if val.is_null() {
4355 return ns;
4356 }
4357 let tab = xmlMalloc(core::mem::size_of::<*mut _xmlNode>()) as *mut *mut _xmlNode;
4358 if tab.is_null() {
4359 xmlFree(ns as *mut c_void);
4360 return ptr::null_mut();
4361 }
4362 *tab = val;
4363 (*ns).nodeTab = tab;
4364 (*ns).nodeNr = 1;
4365 (*ns).nodeMax = 1;
4366 ns
4367}
4368
4369#[no_mangle]
4381pub unsafe extern "C" fn xmlXPathFreeNodeSet(ns: *mut _xmlNodeSet) {
4382 if ns.is_null() {
4383 return;
4384 }
4385 if !(*ns).nodeTab.is_null() {
4386 xmlFree((*ns).nodeTab as *mut c_void);
4387 (*ns).nodeTab = ptr::null_mut();
4388 }
4389 (*ns).nodeNr = 0;
4390 (*ns).nodeMax = 0;
4391 xmlFree(ns as *mut c_void);
4392}
4393
4394#[no_mangle]
4405pub unsafe extern "C" fn xmlXPathCompile(str_: *const xmlChar) -> *mut c_void {
4406 if str_.is_null() {
4407 return ptr::null_mut();
4408 }
4409 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
4410 Ok(s) => s,
4411 Err(_) => return ptr::null_mut(),
4412 };
4413
4414 match crate::xml::xpath::compile(expr_str) {
4415 Some(compiled) => {
4416 let mut map = COMPILED_EXPRS.lock();
4417 let mut counter = NEXT_COMPILED_KEY.lock();
4418 let key = *counter;
4419 *counter += 1;
4420 map.insert(key, Box::new(compiled));
4421 key as *mut c_void
4422 }
4423 None => ptr::null_mut(),
4424 }
4425}
4426
4427#[no_mangle]
4435pub unsafe extern "C" fn xmlXPathFreeCompExpr(comp: *mut c_void) {
4436 if comp.is_null() {
4437 return;
4438 }
4439 let mut map = COMPILED_EXPRS.lock();
4440 map.remove(&(comp as u64));
4441}
4442
4443#[no_mangle]
4452pub unsafe extern "C" fn xmlXPathRegisterNs(
4453 ctxt: *mut _xmlXPathContext,
4454 prefix: *const xmlChar,
4455 ns_uri: *const xmlChar,
4456) -> c_int {
4457 if ctxt.is_null() || prefix.is_null() || ns_uri.is_null() {
4458 return -1;
4459 }
4460 let internal = (*ctxt).extra as *mut XPathContext;
4461 if internal.is_null() {
4462 return -1;
4463 }
4464 let internal = &mut *internal;
4465
4466 let prefix_str = match CStr::from_ptr(prefix as *const c_char).to_str() {
4467 Ok(s) => s,
4468 Err(_) => return -1,
4469 };
4470 let uri_str = match CStr::from_ptr(ns_uri as *const c_char).to_str() {
4471 Ok(s) => s,
4472 Err(_) => return -1,
4473 };
4474
4475 internal.register_namespace(prefix_str, uri_str);
4476 0
4477}
4478
4479#[no_mangle]
4493pub unsafe extern "C" fn xmlXPathRegisterFunc(
4494 ctxt: *mut _xmlXPathContext,
4495 name: *const xmlChar,
4496 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
4497) -> c_int {
4498 if ctxt.is_null() || name.is_null() {
4499 return -1;
4500 }
4501 let internal = (*ctxt).extra as *mut XPathContext;
4502 if internal.is_null() {
4503 return -1;
4504 }
4505 let internal = &mut *internal;
4506
4507 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4508 Ok(s) => s,
4509 Err(_) => return -1,
4510 };
4511
4512 if let Some(func) = f {
4513 let key = (SendSyncPtr((*ctxt).extra), name_str.to_string());
4515 C_FUNCTIONS.lock().insert(key, func);
4516 internal.register_function(name_str, c_func_stub);
4518 }
4519 0
4520}
4521
4522#[no_mangle]
4532pub unsafe extern "C" fn xmlXPathRegisterFuncNS(
4533 ctxt: *mut _xmlXPathContext,
4534 name: *const xmlChar,
4535 ns_uri: *const xmlChar,
4536 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
4537) -> c_int {
4538 if ctxt.is_null() || name.is_null() {
4539 return -1;
4540 }
4541 let internal = (*ctxt).extra as *mut XPathContext;
4542 if internal.is_null() {
4543 return -1;
4544 }
4545 let internal = &mut *internal;
4546
4547 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4548 Ok(s) => s,
4549 Err(_) => return -1,
4550 };
4551 let ns_str = if ns_uri.is_null() {
4552 String::new()
4553 } else {
4554 match CStr::from_ptr(ns_uri as *const c_char).to_str() {
4555 Ok(s) => s.to_string(),
4556 Err(_) => return -1,
4557 }
4558 };
4559
4560 let qualified = if ns_str.is_empty() {
4562 name_str.to_string()
4563 } else {
4564 format!("{{{}}}{}", ns_str, name_str)
4565 };
4566
4567 if let Some(func) = f {
4568 let key = (SendSyncPtr((*ctxt).extra), qualified.clone());
4569 C_FUNCTIONS.lock().insert(key, func);
4570 internal.register_function(&qualified, c_func_stub);
4571 }
4572 0
4573}
4574
4575#[no_mangle]
4584pub unsafe extern "C" fn xmlXPathRegisterVariable(
4585 ctxt: *mut _xmlXPathContext,
4586 name: *const xmlChar,
4587 value: *mut _xmlXPathObject,
4588) -> c_int {
4589 if ctxt.is_null() || name.is_null() || value.is_null() {
4590 return -1;
4591 }
4592 let internal = (*ctxt).extra as *mut XPathContext;
4593 if internal.is_null() {
4594 return -1;
4595 }
4596 let internal = &mut *internal;
4597
4598 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4599 Ok(s) => s,
4600 Err(_) => return -1,
4601 };
4602
4603 let xpath_val = object_to_xpathvalue(value);
4604 internal.register_variable(name_str, xpath_val);
4605 0
4606}
4607
4608#[no_mangle]
4616pub unsafe extern "C" fn xmlXPathNewNodeSet(val: *mut _xmlNode) -> *mut _xmlXPathObject {
4617 let ns = if val.is_null() {
4618 NodeSet::new()
4619 } else {
4620 NodeSet::singleton(val)
4621 };
4622 xpath_to_object(XPathValue::NodeSet(ns))
4623}
4624
4625#[no_mangle]
4633pub unsafe extern "C" fn xmlXPathNewCString(val: *const xmlChar) -> *mut _xmlXPathObject {
4634 if val.is_null() {
4635 return xpath_to_object(XPathValue::String(String::new()));
4636 }
4637 let s = match CStr::from_ptr(val as *const c_char).to_str() {
4638 Ok(s) => s.to_string(),
4639 Err(_) => return ptr::null_mut(),
4640 };
4641 xpath_to_object(XPathValue::String(s))
4642}
4643
4644#[no_mangle]
4652pub extern "C" fn xmlXPathNewFloat(val: f64) -> *mut _xmlXPathObject {
4653 unsafe { xpath_to_object(XPathValue::Number(val)) }
4654}
4655
4656#[no_mangle]
4664pub extern "C" fn xmlXPathNewBoolean(val: c_int) -> *mut _xmlXPathObject {
4665 unsafe { xpath_to_object(XPathValue::Boolean(val != 0)) }
4666}
4667
4668#[no_mangle]
4682pub unsafe extern "C" fn xmlXPtrEval(expr: *const c_char, doc: *mut _xmlDoc) -> *mut _xmlNode {
4683 crate::xml::xpointer::xmlXPtrEval(expr, doc)
4684}
4685
4686#[no_mangle]
4698pub unsafe extern "C" fn xmlXIncludeProcess(doc: *mut _xmlDoc) -> c_int {
4699 crate::xml::xinclude::xinclude_process(doc)
4700}
4701
4702#[no_mangle]
4710pub unsafe extern "C" fn xmlXIncludeProcessFlags(doc: *mut _xmlDoc, flags: c_int) -> c_int {
4711 crate::xml::xinclude::xinclude_process_flags(doc, flags)
4712}
4713
4714#[no_mangle]
4726pub extern "C" fn xmlCatalogLoad(catalogs: *const c_char) -> *mut c_void {
4727 if catalogs.is_null() {
4728 return ptr::null_mut();
4729 }
4730 crate::xml::catalog::load_catalog(catalogs)
4731}
4732
4733#[no_mangle]
4741pub unsafe extern "C" fn xmlCatalogResolvePublic(pubID: *const xmlChar) -> *mut xmlChar {
4742 if pubID.is_null() {
4743 return ptr::null_mut();
4744 }
4745 crate::xml::catalog::resolve_public(pubID)
4746}
4747
4748#[no_mangle]
4756pub unsafe extern "C" fn xmlCatalogResolveSystem(sysID: *const xmlChar) -> *mut xmlChar {
4757 if sysID.is_null() {
4758 return ptr::null_mut();
4759 }
4760 crate::xml::catalog::resolve_system(sysID)
4761}
4762
4763#[no_mangle]
4771pub unsafe extern "C" fn xmlCatalogResolveURI(URI: *const xmlChar) -> *mut xmlChar {
4772 if URI.is_null() {
4773 return ptr::null_mut();
4774 }
4775 crate::xml::catalog::resolve_uri(URI)
4776}
4777
4778#[no_mangle]
4786pub extern "C" fn xmlCatalogSetDefaults(allow: c_int) {
4787 crate::xml::catalog::set_defaults(allow)
4788}
4789
4790#[no_mangle]
4798pub extern "C" fn xmlCatalogGetDefaults() -> c_int {
4799 crate::xml::catalog::get_defaults()
4800}
4801
4802#[no_mangle]
4810pub unsafe extern "C" fn xmlCatalogAdd(
4811 type_: *const xmlChar,
4812 orig: *const xmlChar,
4813 replace: *const xmlChar,
4814) -> c_int {
4815 if type_.is_null() || orig.is_null() || replace.is_null() {
4816 return -1;
4817 }
4818 crate::xml::catalog::add(type_, orig, replace)
4819}
4820
4821#[no_mangle]
4829pub unsafe extern "C" fn xmlCatalogRemove(value: *const xmlChar) -> c_int {
4830 if value.is_null() {
4831 return 0;
4832 }
4833 crate::xml::catalog::remove(value)
4834}
4835
4836#[no_mangle]
4844pub extern "C" fn xmlCatalogCleanup() {
4845 crate::xml::catalog::cleanup();
4846}
4847
4848#[no_mangle]
4856pub extern "C" fn xmlCatalogConvert() -> *mut _xmlDoc {
4857 unsafe { crate::xml::catalog::convert() }
4859}
4860
4861#[no_mangle]
4873pub unsafe extern "C" fn htmlParseFile(
4874 _filename: *const c_char,
4875 _encoding: *const c_char,
4876) -> *mut _xmlDoc {
4877 ptr::null_mut()
4879}
4880
4881#[no_mangle]
4889pub unsafe extern "C" fn htmlParseMemory(_buffer: *const c_char, _size: c_int) -> *mut _xmlDoc {
4890 ptr::null_mut()
4892}
4893
4894#[no_mangle]
4902pub unsafe extern "C" fn htmlParseDoc(
4903 _cur: *const xmlChar,
4904 _encoding: *const c_char,
4905) -> *mut _xmlDoc {
4906 ptr::null_mut()
4908}
4909
4910#[no_mangle]
4919pub unsafe extern "C" fn htmlCreateFileParserCtxt(
4920 _filename: *const c_char,
4921 _encoding: *const c_char,
4922) -> *mut c_void {
4923 ptr::null_mut()
4925}
4926
4927#[no_mangle]
4935pub extern "C" fn htmlFreeParserCtxt(_ctxt: *mut c_void) {
4936 }
4938
4939#[no_mangle]
4947pub extern "C" fn htmlInitParser() {
4948 }
4950
4951#[no_mangle]
4959pub extern "C" fn htmlCleanupParser() {
4960 }
4962
4963#[no_mangle]
4975pub unsafe extern "C" fn xmlNewValidCtxt() -> *mut _xmlValidCtxt {
4976 crate::xml::validation::new_valid_ctxt()
4977}
4978
4979#[no_mangle]
4987pub unsafe extern "C" fn xmlFreeValidCtxt(ctxt: *mut _xmlValidCtxt) {
4988 crate::xml::validation::free_valid_ctxt(ctxt);
4989}
4990
4991#[no_mangle]
5002pub unsafe extern "C" fn xmlSetValidErrors(
5003 ctxt: *mut _xmlValidCtxt,
5004 err: Option<xmlGenericErrorFunc>,
5005 warn: Option<xmlGenericErrorFunc>,
5006 data: *mut c_void,
5007) {
5008 crate::xml::validation::set_valid_errors(ctxt, err, warn, data);
5009}
5010
5011#[no_mangle]
5019pub unsafe extern "C" fn xmlValidateDocument(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5020 crate::xml::validation::validate_document(ctxt, doc)
5021}
5022
5023#[no_mangle]
5031pub unsafe extern "C" fn xmlValidateDocumentFinal(
5032 ctxt: *mut _xmlValidCtxt,
5033 doc: *mut _xmlDoc,
5034) -> c_int {
5035 crate::xml::validation::validate_document_final(ctxt, doc)
5036}
5037
5038#[no_mangle]
5048pub unsafe extern "C" fn xmlValidateElement(
5049 ctxt: *mut _xmlValidCtxt,
5050 doc: *mut _xmlDoc,
5051 elem: *mut _xmlNode,
5052) -> c_int {
5053 crate::xml::validation::validate_element(ctxt, doc, elem)
5054}
5055
5056#[no_mangle]
5067pub unsafe extern "C" fn xmlValidateAttributeDecl(
5068 ctxt: *mut _xmlValidCtxt,
5069 doc: *mut _xmlDoc,
5070 elem: *mut _xmlNode,
5071 attr: *mut _xmlAttribute,
5072) -> c_int {
5073 crate::xml::validation::validate_attribute_decl(ctxt, doc, elem, attr)
5074}
5075
5076#[no_mangle]
5084pub unsafe extern "C" fn xmlValidateAttributeValue(atype: c_int, value: *const xmlChar) -> c_int {
5085 crate::xml::validation::validate_attribute_value(atype, value)
5086}
5087
5088#[no_mangle]
5098pub unsafe extern "C" fn xmlValidateNotationUse(
5099 ctxt: *mut _xmlValidCtxt,
5100 doc: *mut _xmlDoc,
5101 notation_name: *const xmlChar,
5102) -> c_int {
5103 crate::xml::validation::validate_notation_use(ctxt, doc, notation_name)
5104}
5105
5106#[no_mangle]
5117pub unsafe extern "C" fn xmlValidateID(
5118 ctxt: *mut _xmlValidCtxt,
5119 doc: *mut _xmlDoc,
5120 node: *mut _xmlNode,
5121 value: *const xmlChar,
5122) -> c_int {
5123 crate::xml::validation::validate_id(ctxt, doc, node, value)
5124}
5125
5126#[no_mangle]
5137pub unsafe extern "C" fn xmlValidateIDRef(
5138 ctxt: *mut _xmlValidCtxt,
5139 doc: *mut _xmlDoc,
5140 node: *mut _xmlNode,
5141 value: *const xmlChar,
5142) -> c_int {
5143 crate::xml::validation::validate_id_ref(ctxt, doc, node, value)
5144}
5145
5146#[no_mangle]
5157pub unsafe extern "C" fn xmlValidateIDRefs(
5158 ctxt: *mut _xmlValidCtxt,
5159 doc: *mut _xmlDoc,
5160 node: *mut _xmlNode,
5161 value: *const xmlChar,
5162) -> c_int {
5163 crate::xml::validation::validate_id_refs(ctxt, doc, node, value)
5164}
5165
5166#[no_mangle]
5174pub unsafe extern "C" fn xmlValidateNmtoken(value: *const xmlChar) -> c_int {
5175 crate::xml::validation::validate_nmtoken(value)
5176}
5177
5178#[no_mangle]
5186pub unsafe extern "C" fn xmlValidateNmtokens(value: *const xmlChar) -> c_int {
5187 crate::xml::validation::validate_nmtokens(value)
5188}
5189
5190#[no_mangle]
5198pub unsafe extern "C" fn xmlValidateName(value: *const xmlChar) -> c_int {
5199 crate::xml::validation::validate_name(value)
5200}
5201
5202#[no_mangle]
5210pub unsafe extern "C" fn xmlValidateNames(value: *const xmlChar) -> c_int {
5211 crate::xml::validation::validate_names(value)
5212}
5213
5214#[no_mangle]
5222pub unsafe extern "C" fn xmlValidateRoot(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5223 crate::xml::validation::validate_root(ctxt, doc)
5224}
5225
5226#[no_mangle]
5236pub unsafe extern "C" fn xmlValidateContent(
5237 ctxt: *mut _xmlValidCtxt,
5238 node: *mut _xmlNode,
5239 doc: *mut _xmlDoc,
5240) -> c_int {
5241 crate::xml::validation::validate_content(ctxt, node, doc)
5242}
5243
5244#[no_mangle]
5252pub unsafe extern "C" fn xmlIsMixedElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
5253 crate::xml::validation::is_mixed_element(doc, name)
5254}
5255
5256#[no_mangle]
5264pub unsafe extern "C" fn xmlIsEmptyElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
5265 crate::xml::validation::is_empty_element(doc, name)
5266}
5267
5268#[no_mangle]
5278pub unsafe extern "C" fn xmlValidateDtd(
5279 ctxt: *mut _xmlValidCtxt,
5280 doc: *mut _xmlDoc,
5281 dtd: *mut _xmlDtd,
5282) -> c_int {
5283 crate::xml::validation::validate_dtd(ctxt, doc, dtd)
5284}
5285
5286#[no_mangle]
5294pub unsafe extern "C" fn xmlValidateDtdFinal(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5295 crate::xml::validation::validate_dtd_final(ctxt, doc)
5296}
5297
5298#[no_mangle]
5308pub unsafe extern "C" fn xmlValidateEnumeration(
5309 ctxt: *mut _xmlValidCtxt,
5310 value: *const xmlChar,
5311 tree: *mut _xmlEnumeration,
5312) -> c_int {
5313 crate::xml::validation::validate_enumeration(ctxt, value, tree)
5314}
5315
5316#[no_mangle]
5330pub extern "C" fn xmlGetBinaryPath() -> *mut c_char {
5331 ptr::null_mut()
5333}
5334
5335#[no_mangle]
5343pub extern "C" fn xmlGetHomeOfBinary() -> *mut c_char {
5344 ptr::null_mut()
5346}