1#![allow(non_snake_case)]
98#![allow(unused_variables)]
99#![allow(clippy::missing_safety_doc)]
100#![allow(clippy::not_unsafe_ptr_arg_deref)]
101
102use core::ffi::c_void;
113use core::ptr;
114use once_cell::sync::Lazy;
115use parking_lot::Mutex;
116use std::collections::HashMap;
117use std::ffi::{CStr, CString};
118use std::mem::size_of;
119use std::os::raw::{c_char, c_int, c_long, c_uint, c_ulong};
120
121use crate::xml::xpath::ast::CompiledExpr;
122use crate::xml::xpath::context::{BoxedXPathFunction, XPathContext};
123use crate::xml::xpath::types::{NodeSet, XPathValue};
124
125use crate::abi::allocator::*;
126use crate::abi::callbacks::*;
127use crate::abi::structs::*;
128use crate::abi::types::*;
129
130#[no_mangle]
145pub unsafe extern "C" fn xmlInitParser() {
146 crate::internal::globals::init_parser();
147}
148
149#[no_mangle]
162pub const unsafe extern "C" fn xmlInitGlobals() {
163 }
165
166#[no_mangle]
176pub const unsafe extern "C" fn xmlInitializeGlobalState(_gs: *mut c_void) {
177 }
181
182#[no_mangle]
191pub const extern "C" fn xmlInitializeDict() -> c_int {
192 0
195}
196
197#[no_mangle]
207pub const extern "C" fn xmlInitializePredefinedEntities() {
208 }
210
211#[no_mangle]
220pub const extern "C" fn xmlCleanupPredefinedEntities() {
221 }
223
224#[no_mangle]
235pub const extern "C" fn xmlDefaultSAXHandlerInit() {
236 }
239
240static SAX2_DEFAULT_VERSION: core::sync::atomic::AtomicI32 = core::sync::atomic::AtomicI32::new(2);
243#[no_mangle]
252pub extern "C" fn xmlSAXDefaultVersion(version: c_int) -> c_int {
253 use core::sync::atomic::Ordering;
254 let ret = SAX2_DEFAULT_VERSION.load(Ordering::Relaxed);
255 if version != 1 && version != 2 {
256 return -1;
257 }
258 SAX2_DEFAULT_VERSION.store(version, Ordering::Relaxed);
259 ret
260}
261
262#[no_mangle]
272pub unsafe extern "C" fn xmlSAXVersion(
273 hdlr: *mut crate::abi::structs::_xmlSAXHandler,
274 version: c_int,
275) -> c_int {
276 if hdlr.is_null() {
277 return -1;
278 }
279 if version != 1 && version != 2 {
280 return -1;
281 }
282 unsafe {
284 crate::xml::sax::dispatch::xmlSAX2InitDefaultSAXHandler(hdlr);
285 let h = &mut *hdlr;
286 if version == 2 {
287 h.initialized = crate::abi::constants::XML_SAX2_MAGIC as c_uint;
288 } else {
289 h.initialized = 1;
290 }
291 }
292 0
293}
294
295#[no_mangle]
306pub extern "C" fn xmlHasFeature(feature: c_int) -> c_int {
307 if (1..=24).contains(&feature) {
310 1
311 } else {
312 0
313 }
314}
315
316#[no_mangle]
328pub const unsafe extern "C" fn xmlCleanupGlobals() {
329 }
331
332#[no_mangle]
342pub unsafe extern "C" fn xmlCleanupParser() {
343 crate::internal::globals::cleanup_parser();
344}
345
346#[no_mangle]
354pub extern "C" fn xmlNewMutex() -> *mut c_void {
355 crate::xml::threads::new_mutex()
356}
357
358#[no_mangle]
366pub unsafe extern "C" fn xmlFreeMutex(tok: *mut c_void) {
367 crate::xml::threads::free_mutex(tok);
368}
369
370#[no_mangle]
378pub unsafe extern "C" fn xmlMutexLock(tok: *mut c_void) {
379 crate::xml::threads::mutex_lock(tok);
380}
381
382#[no_mangle]
390pub unsafe extern "C" fn xmlMutexUnlock(tok: *mut c_void) {
391 crate::xml::threads::mutex_unlock(tok);
392}
393
394#[no_mangle]
402pub extern "C" fn xmlNewRMutex() -> *mut c_void {
403 crate::xml::threads::new_rmutex()
404}
405
406#[no_mangle]
414pub unsafe extern "C" fn xmlFreeRMutex(tok: *mut c_void) {
415 crate::xml::threads::free_rmutex(tok);
416}
417
418#[no_mangle]
426pub unsafe extern "C" fn xmlRMutexLock(tok: *mut c_void) {
427 crate::xml::threads::rmutex_lock(tok);
428}
429
430#[no_mangle]
438pub unsafe extern "C" fn xmlRMutexUnlock(tok: *mut c_void) {
439 crate::xml::threads::rmutex_unlock(tok);
440}
441
442#[no_mangle]
452pub const extern "C" fn xmlCheckThreadLocalStorage() -> c_int {
453 0
456}
457
458#[no_mangle]
469pub unsafe extern "C" fn xmlInitThreads() {
470 let _ = unsafe { crate::internal::globals::init_threads() };
471}
472
473#[no_mangle]
481pub unsafe extern "C" fn xmlCleanupThreads() {
482 crate::xml::threads::cleanup_threads();
483}
484
485#[no_mangle]
493pub extern "C" fn xmlIsInitialized() -> c_int {
494 if crate::abi::versioning::is_initialized() {
495 1
496 } else {
497 0
498 }
499}
500
501#[no_mangle]
510pub const unsafe extern "C" fn xmlLockLibrary() {
511 crate::xml::threads::lock_library();
512}
513
514#[no_mangle]
522pub const unsafe extern "C" fn xmlUnlockLibrary() {
523 crate::xml::threads::unlock_library();
524}
525
526#[no_mangle]
543pub unsafe extern "C" fn xmlSetGenericErrorFunc(
544 ctx: *mut c_void,
545 handler: Option<xmlGenericErrorFunc>,
546) {
547 unsafe { crate::xml::errors::set_generic_error_func(ctx, handler) };
549}
550
551#[no_mangle]
563pub unsafe extern "C" fn xmlSetStructuredErrorFunc(
564 ctx: *mut c_void,
565 handler: Option<xmlStructuredErrorFunc>,
566) {
567 unsafe { crate::xml::errors::set_structured_error_func(ctx, handler) };
569}
570
571#[no_mangle]
582pub extern "C" fn xmlGetLastError() -> *mut _xmlError {
583 crate::xml::errors::get_last_error()
584}
585
586#[no_mangle]
600pub const unsafe extern "C" fn xmlCopyError(from: *const _xmlError, to: *mut _xmlError) -> c_int {
601 unsafe { crate::xml::errors::copy_error(from, to) }
603}
604
605#[no_mangle]
617pub const unsafe extern "C" fn xmlResetError(err: *mut _xmlError) {
618 unsafe { crate::xml::errors::reset_error(err) };
620}
621
622#[no_mangle]
635pub unsafe extern "C" fn xmlRaiseError(
636 ctxt: *mut c_void,
637 ctxt2: *mut c_void,
638 ctxt3: *mut c_void,
639 ctxt4: *mut c_void,
640 ctxt5: *mut c_void,
641 domain: c_int,
642 code: c_int,
643 level: c_int,
644 file: *const c_char,
645 line: c_int,
646 str1: *const c_char,
647 str2: *const c_char,
648 str3: *const c_char,
649 int1: c_int,
650 int2: c_int,
651 msg: *const c_char,
652) {
653 unsafe {
655 crate::xml::errors::raise_error(
656 ctxt, ctxt2, ctxt3, ctxt4, ctxt5, domain, code, level, file, line, str1, str2, str3,
657 int1, int2, msg,
658 );
659 }
660}
661
662#[no_mangle]
670pub extern "C" fn xmlResetLastError() {
671 crate::xml::errors::reset_last_error();
672}
673
674#[no_mangle]
690pub unsafe extern "C" fn xmlStrdup(cur: *const xmlChar) -> *mut xmlChar {
691 if cur.is_null() {
692 return ptr::null_mut();
693 }
694 let len = unsafe { xmlStrlen(cur) };
695 let size = len + 1;
696 let new_ptr = unsafe { xmlMallocImpl(size as usize) };
697 if new_ptr.is_null() {
698 return ptr::null_mut();
699 }
700 unsafe {
701 ptr::copy_nonoverlapping(cur, new_ptr as *mut u8, size as usize);
702 }
703 new_ptr as *mut xmlChar
704}
705
706#[no_mangle]
718pub unsafe extern "C" fn xmlStrndup(cur: *const xmlChar, len: c_int) -> *mut xmlChar {
719 if cur.is_null() || len <= 0 {
720 return ptr::null_mut();
721 }
722 let size = len as usize + 1;
723 let new_ptr = unsafe { xmlMallocImpl(size) };
724 if new_ptr.is_null() {
725 return ptr::null_mut();
726 }
727 unsafe {
728 ptr::copy_nonoverlapping(cur, new_ptr as *mut u8, len as usize);
729 *(new_ptr.add(len as usize) as *mut u8) = 0;
730 }
731 new_ptr as *mut xmlChar
732}
733
734#[no_mangle]
746pub unsafe extern "C" fn xmlStrlen(str: *const xmlChar) -> c_int {
747 if str.is_null() {
748 return 0;
749 }
750 unsafe { libc::strlen(str as *const c_char) as c_int }
751}
752
753#[no_mangle]
766pub const unsafe extern "C" fn xmlStrchr(str: *const xmlChar, val: xmlChar) -> *const xmlChar {
767 if str.is_null() {
768 return ptr::null();
769 }
770 unsafe {
771 let mut cur = str;
772 while *cur != 0 {
773 if *cur == val {
774 return cur;
775 }
776 cur = cur.add(1);
777 }
778 ptr::null()
779 }
780}
781
782#[no_mangle]
793pub unsafe extern "C" fn xmlStrcmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
794 if str1.is_null() && str2.is_null() {
795 return 0;
796 }
797 if str1.is_null() {
798 return -1;
799 }
800 if str2.is_null() {
801 return 1;
802 }
803 unsafe { libc::strcmp(str1 as *const c_char, str2 as *const c_char) as c_int }
804}
805
806#[no_mangle]
814pub unsafe extern "C" fn xmlStrncmp(
815 str1: *const xmlChar,
816 str2: *const xmlChar,
817 len: c_int,
818) -> c_int {
819 if len <= 0 {
820 return 0;
821 }
822 if str1.is_null() && str2.is_null() {
823 return 0;
824 }
825 if str1.is_null() {
826 return -1;
827 }
828 if str2.is_null() {
829 return 1;
830 }
831 unsafe { libc::strncmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int }
832}
833
834#[no_mangle]
842pub unsafe extern "C" fn xmlStrcasecmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
843 if str1.is_null() && str2.is_null() {
844 return 0;
845 }
846 if str1.is_null() {
847 return -1;
848 }
849 if str2.is_null() {
850 return 1;
851 }
852 unsafe { libc::strcasecmp(str1 as *const c_char, str2 as *const c_char) as c_int }
853}
854
855#[no_mangle]
863pub unsafe extern "C" fn xmlStrncasecmp(
864 str1: *const xmlChar,
865 str2: *const xmlChar,
866 len: c_int,
867) -> c_int {
868 if len <= 0 {
869 return 0;
870 }
871 if str1.is_null() && str2.is_null() {
872 return 0;
873 }
874 if str1.is_null() {
875 return -1;
876 }
877 if str2.is_null() {
878 return 1;
879 }
880 unsafe {
881 libc::strncasecmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int
882 }
883}
884
885#[no_mangle]
895pub unsafe extern "C" fn xmlStrEqual(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
896 if str1.is_null() && str2.is_null() {
897 return 1;
898 }
899 if str1.is_null() || str2.is_null() {
900 return 0;
901 }
902 unsafe { (libc::strcmp(str1 as *const c_char, str2 as *const c_char) == 0) as c_int }
903}
904
905#[no_mangle]
914pub unsafe extern "C" fn xmlBuildQName(
915 ncname: *const xmlChar,
916 prefix: *const xmlChar,
917 memory: *mut xmlChar,
918 len: c_int,
919) -> *mut xmlChar {
920 crate::xml::string::build_qname(ncname, prefix, memory, len)
921}
922
923#[no_mangle]
931pub unsafe extern "C" fn xmlSplitQName2(
932 name: *const xmlChar,
933 prefix: *mut *mut xmlChar,
934) -> *mut xmlChar {
935 crate::xml::string::split_qname2(name, prefix)
936}
937
938#[no_mangle]
948pub unsafe extern "C" fn xmlSplitQName3(name: *const xmlChar, len: *mut c_int) -> *mut xmlChar {
949 crate::xml::string::split_qname3(name, len)
950}
951
952#[no_mangle]
967pub unsafe extern "C" fn xmlSplitQName(
968 _ctxt: *mut _xmlParserCtxt,
969 name: *const xmlChar,
970 prefix: *mut *mut xmlChar,
971) -> *mut xmlChar {
972 crate::xml::string::split_qname2(name, prefix)
973}
974
975#[no_mangle]
983pub const unsafe extern "C" fn xmlUTF8Strlen(utf: *const xmlChar) -> c_int {
984 crate::xml::string::utf8_strlen(utf)
985}
986
987#[no_mangle]
995pub const unsafe extern "C" fn xmlUTF8Size(utf: *const xmlChar) -> c_int {
996 crate::xml::string::utf8_size(utf)
997}
998
999#[no_mangle]
1007pub const unsafe extern "C" fn xmlCheckUTF8(utf: *const xmlChar) -> c_int {
1008 crate::xml::string::check_utf8(utf)
1009}
1010
1011#[no_mangle]
1022pub unsafe extern "C" fn xmlStrQEqual(
1023 pref: *const xmlChar,
1024 name: *const xmlChar,
1025 str: *const xmlChar,
1026) -> c_int {
1027 if name.is_null() || str.is_null() {
1028 return 0;
1029 }
1030 if pref.is_null() {
1031 return unsafe { xmlStrEqual(name, str) };
1032 }
1033 let pref_len = unsafe { xmlStrlen(pref) };
1035 let name_len = unsafe { xmlStrlen(name) };
1036 let total_len = pref_len + 1 + name_len;
1037 let str_len = unsafe { xmlStrlen(str) };
1038 if total_len != str_len {
1039 return 0;
1040 }
1041 if unsafe {
1043 libc::strncmp(
1044 pref as *const c_char,
1045 str as *const c_char,
1046 pref_len as usize,
1047 )
1048 } != 0
1049 {
1050 return 0;
1051 }
1052 if unsafe { *str.add(pref_len as usize) } != b':' as xmlChar {
1054 return 0;
1055 }
1056 (unsafe {
1058 libc::strncmp(
1059 name as *const c_char,
1060 str.add((pref_len + 1) as usize) as *const c_char,
1061 name_len as usize,
1062 ) == 0
1063 }) as c_int
1064}
1065
1066#[no_mangle]
1080pub unsafe extern "C" fn xmlStrcat(cur: *mut xmlChar, add: *const xmlChar) -> *mut xmlChar {
1081 if add.is_null() {
1082 return cur;
1083 }
1084 if cur.is_null() {
1085 return unsafe { xmlStrdup(add) };
1086 }
1087 let cur_len = unsafe { xmlStrlen(cur) } as usize;
1088 let add_len = unsafe { xmlStrlen(add) } as usize;
1089 let new_size = cur_len + add_len + 1;
1090 let new_ptr = unsafe { xmlReallocImpl(cur as *mut c_void, new_size) };
1091 if new_ptr.is_null() {
1092 unsafe { xmlFreeImpl(cur as *mut c_void) };
1096 return ptr::null_mut();
1097 }
1098 unsafe {
1099 ptr::copy_nonoverlapping(add, (new_ptr as *mut u8).add(cur_len), add_len);
1100 *((new_ptr as *mut u8).add(cur_len + add_len)) = 0;
1101 }
1102 new_ptr as *mut xmlChar
1103}
1104
1105#[no_mangle]
1117pub unsafe extern "C" fn xmlStrncat(
1118 cur: *mut xmlChar,
1119 add: *const xmlChar,
1120 len: c_int,
1121) -> *mut xmlChar {
1122 if add.is_null() || len <= 0 {
1123 return cur;
1124 }
1125 let len = len as usize;
1126 if cur.is_null() {
1127 return unsafe { xmlStrndup(add, len as c_int) };
1128 }
1129 let cur_len = unsafe { xmlStrlen(cur) } as usize;
1130 let new_size = cur_len + len + 1;
1131 let new_ptr = unsafe { xmlReallocImpl(cur as *mut c_void, new_size) };
1132 if new_ptr.is_null() {
1133 unsafe { xmlFreeImpl(cur as *mut c_void) };
1137 return ptr::null_mut();
1138 }
1139 unsafe {
1140 ptr::copy_nonoverlapping(add, (new_ptr as *mut u8).add(cur_len), len);
1141 *((new_ptr as *mut u8).add(cur_len + len)) = 0;
1142 }
1143 new_ptr as *mut xmlChar
1144}
1145
1146#[no_mangle]
1154pub unsafe extern "C" fn xmlStrncatNew(
1155 str1: *const xmlChar,
1156 str2: *const xmlChar,
1157 len: c_int,
1158) -> *mut xmlChar {
1159 let mut result: *mut xmlChar = ptr::null_mut();
1160 if !str1.is_null() {
1161 result = unsafe { xmlStrdup(str1) };
1162 }
1163 if !str2.is_null() && len > 0 {
1164 result = unsafe { xmlStrncat(result, str2, len) };
1165 }
1166 result
1167}
1168
1169#[no_mangle]
1182pub unsafe extern "C" fn xmlStrcpy(dst: *mut xmlChar, src: *const xmlChar) -> *mut xmlChar {
1183 if dst.is_null() || src.is_null() {
1184 return dst;
1185 }
1186 let len = unsafe { xmlStrlen(src) } as usize + 1;
1187 unsafe {
1188 ptr::copy_nonoverlapping(src, dst, len);
1189 }
1190 dst
1191}
1192
1193#[no_mangle]
1201pub unsafe extern "C" fn xmlStrncpy(
1202 dst: *mut xmlChar,
1203 src: *const xmlChar,
1204 len: c_int,
1205) -> *mut xmlChar {
1206 if dst.is_null() || src.is_null() || len <= 0 {
1207 return dst;
1208 }
1209 let len = len as usize;
1210 let src_len = unsafe { xmlStrlen(src) } as usize;
1211 let copy_len = if src_len < len { src_len } else { len - 1 };
1212 unsafe {
1213 ptr::copy_nonoverlapping(src, dst, copy_len);
1214 *dst.add(copy_len) = 0;
1215 }
1216 dst
1217}
1218
1219#[no_mangle]
1229pub unsafe extern "C" fn xmlStrsub(str: *const xmlChar, start: c_int, len: c_int) -> *mut xmlChar {
1230 if str.is_null() || start < 0 || len < 0 {
1231 return ptr::null_mut();
1232 }
1233 let str_len = unsafe { xmlStrlen(str) };
1234 if start >= str_len {
1235 return unsafe { xmlStrdup(b"\0" as *const u8 as *const xmlChar) };
1236 }
1237 let actual_len = if start + len > str_len {
1238 str_len - start
1239 } else {
1240 len
1241 };
1242 unsafe { xmlStrndup(str.add(start as usize), actual_len) }
1243}
1244
1245#[no_mangle]
1262pub unsafe extern "C" fn xmlNewDoc(version: *const xmlChar) -> *mut _xmlDoc {
1263 crate::xml::tree::new_doc(version)
1264}
1265
1266#[no_mangle]
1278pub unsafe extern "C" fn xmlFreeDoc(doc: *mut _xmlDoc) {
1279 crate::xml::tree::free_doc(doc);
1280}
1281
1282#[no_mangle]
1292pub unsafe extern "C" fn xmlGetDocCompressMode(doc: *mut _xmlDoc) -> c_int {
1293 crate::xml::tree::xmlGetDocCompressMode(doc)
1294}
1295
1296#[no_mangle]
1304pub unsafe extern "C" fn xmlSetDocCompressMode(doc: *mut _xmlDoc, mode: c_int) {
1305 crate::xml::tree::xmlSetDocCompressMode(doc, mode);
1306}
1307
1308#[no_mangle]
1322pub unsafe extern "C" fn xmlNewNode(ns: *mut _xmlNs, name: *const xmlChar) -> *mut _xmlNode {
1323 crate::xml::tree::new_node(ns, name)
1324}
1325
1326#[no_mangle]
1339pub unsafe extern "C" fn xmlFreeNode(node: *mut _xmlNode) {
1340 crate::xml::tree::free_node(node);
1341}
1342
1343#[no_mangle]
1360pub unsafe extern "C" fn xmlFreeNodeList(node: *mut _xmlNode) {
1361 crate::xml::tree::free_node_list(node);
1362}
1363
1364#[no_mangle]
1376pub unsafe extern "C" fn xmlUnlinkNode(node: *mut _xmlNode) {
1377 crate::xml::tree::unlink_node(node);
1378}
1379
1380#[no_mangle]
1396pub unsafe extern "C" fn xmlSAX2InitDefaultSAXHandler(
1397 handler: *mut crate::abi::structs::_xmlSAXHandler,
1398 _warning: c_int,
1399) {
1400 crate::xml::sax::dispatch::xmlSAX2InitDefaultSAXHandler(handler);
1401}
1402
1403#[no_mangle]
1422pub unsafe extern "C" fn xmlSAX2InitHtmlDefaultSAXHandler(
1423 handler: *mut crate::abi::structs::_xmlSAXHandler,
1424) {
1425 if handler.is_null() {
1426 return;
1427 }
1428 unsafe {
1430 if (*handler).initialized != 0 {
1432 return;
1433 }
1434 crate::xml::sax::dispatch::xmlSAX2InitDefaultSAXHandler(handler);
1435 let h = &mut *handler;
1436 h.resolveEntity = None;
1437 h.getParameterEntity = None;
1438 h.entityDecl = None;
1439 h.attributeDecl = None;
1440 h.elementDecl = None;
1441 h.notationDecl = None;
1442 h.unparsedEntityDecl = None;
1443 h.reference = None;
1444 h.externalSubset = None;
1445 h.initialized = 1;
1446 }
1447}
1448
1449#[no_mangle]
1463pub unsafe extern "C" fn xmlAddChild(parent: *mut _xmlNode, cur: *mut _xmlNode) -> *mut _xmlNode {
1464 crate::xml::tree::add_child(parent, cur)
1465}
1466
1467#[no_mangle]
1479pub unsafe extern "C" fn xmlAddSibling(
1480 cur: *mut _xmlNode,
1481 sibling: *mut _xmlNode,
1482) -> *mut _xmlNode {
1483 crate::xml::tree::add_sibling(cur, sibling)
1484}
1485
1486#[no_mangle]
1505pub unsafe extern "C" fn xmlNewChild(
1506 parent: *mut _xmlNode,
1507 ns: *mut _xmlNs,
1508 name: *const xmlChar,
1509 content: *const xmlChar,
1510) -> *mut _xmlNode {
1511 if parent.is_null() || name.is_null() {
1515 return ptr::null_mut();
1516 }
1517 let node = crate::xml::tree::new_child(parent, ns, name);
1518 if node.is_null() {
1519 return ptr::null_mut();
1520 }
1521 if !content.is_null() {
1522 let text = crate::xml::tree::new_text(content);
1523 if !text.is_null() {
1524 crate::xml::tree::add_child(node, text);
1525 }
1526 }
1527 node
1528}
1529
1530#[no_mangle]
1545pub unsafe extern "C" fn xmlDocSetRootElement(
1546 doc: *mut _xmlDoc,
1547 root: *mut _xmlNode,
1548) -> *mut _xmlNode {
1549 crate::xml::tree::doc_set_root_element(doc, root)
1550}
1551
1552#[no_mangle]
1562pub extern "C" fn xmlDocGetRootElement(doc: *const _xmlDoc) -> *mut _xmlNode {
1563 crate::xml::tree::doc_get_root_element(doc as *mut _xmlDoc)
1564}
1565
1566#[no_mangle]
1579pub unsafe extern "C" fn xmlCopyNode(node: *const _xmlNode, extended: c_int) -> *mut _xmlNode {
1580 crate::xml::tree::copy_node(node, extended)
1581}
1582
1583#[no_mangle]
1593pub unsafe extern "C" fn xmlCopyDoc(doc: *const _xmlDoc, recursive: c_int) -> *mut _xmlDoc {
1594 crate::xml::tree::copy_doc(doc, recursive)
1595}
1596
1597#[no_mangle]
1608pub unsafe extern "C" fn xmlNewText(content: *const xmlChar) -> *mut _xmlNode {
1609 crate::xml::tree::new_text(content)
1610}
1611
1612#[no_mangle]
1620pub unsafe extern "C" fn xmlNewComment(content: *const xmlChar) -> *mut _xmlNode {
1621 crate::xml::tree::new_comment(content)
1622}
1623
1624#[no_mangle]
1632pub unsafe extern "C" fn xmlNewPI(name: *const xmlChar, content: *const xmlChar) -> *mut _xmlNode {
1633 crate::xml::tree::new_pi(name, content)
1634}
1635
1636#[no_mangle]
1644pub unsafe extern "C" fn xmlNewCDataBlock(
1645 doc: *mut _xmlDoc,
1646 content: *const xmlChar,
1647 len: c_int,
1648) -> *mut _xmlNode {
1649 crate::xml::tree::new_cdata_block(doc, content, len)
1650}
1651
1652#[no_mangle]
1666pub unsafe extern "C" fn xmlNewNs(
1667 node: *mut _xmlNode,
1668 href: *const xmlChar,
1669 prefix: *const xmlChar,
1670) -> *mut _xmlNs {
1671 crate::xml::tree::new_ns(node, href, prefix)
1672}
1673
1674#[no_mangle]
1682pub unsafe extern "C" fn xmlSetNs(node: *mut _xmlNode, ns: *mut _xmlNs) {
1683 crate::xml::tree::set_ns(node, ns);
1684}
1685
1686#[no_mangle]
1694pub unsafe extern "C" fn xmlGetNsList(
1695 doc: *mut _xmlDoc,
1696 node: *const _xmlNode,
1697) -> *mut *mut _xmlNs {
1698 crate::xml::tree::get_ns_list(doc, node as *mut _xmlNode)
1699}
1700
1701#[no_mangle]
1709pub unsafe extern "C" fn xmlSearchNs(
1710 doc: *mut _xmlDoc,
1711 node: *mut _xmlNode,
1712 nameSpace: *const xmlChar,
1713) -> *mut _xmlNs {
1714 crate::xml::tree::search_ns(doc, node, nameSpace)
1715}
1716
1717#[no_mangle]
1725pub unsafe extern "C" fn xmlSearchNsByHref(
1726 doc: *mut _xmlDoc,
1727 node: *mut _xmlNode,
1728 href: *const xmlChar,
1729) -> *mut _xmlNs {
1730 crate::xml::tree::search_ns_by_href(doc, node, href)
1731}
1732
1733#[no_mangle]
1750pub unsafe extern "C" fn xmlSetProp(
1751 node: *mut _xmlNode,
1752 name: *const xmlChar,
1753 value: *const xmlChar,
1754) -> *mut _xmlAttr {
1755 crate::xml::tree::set_prop(node, name, value)
1756}
1757
1758#[no_mangle]
1768pub unsafe extern "C" fn xmlGetProp(node: *const _xmlNode, name: *const xmlChar) -> *mut xmlChar {
1769 crate::xml::tree::get_prop(node as *mut _xmlNode, name)
1770}
1771
1772#[no_mangle]
1780pub unsafe extern "C" fn xmlGetNsProp(
1781 node: *const _xmlNode,
1782 name: *const xmlChar,
1783 nameSpace: *const xmlChar,
1784) -> *mut xmlChar {
1785 crate::xml::tree::get_ns_prop(node as *mut _xmlNode, name, nameSpace)
1786}
1787
1788#[no_mangle]
1797pub unsafe extern "C" fn xmlSetNsProp(
1798 node: *mut _xmlNode,
1799 ns: *mut _xmlNs,
1800 name: *const xmlChar,
1801 value: *const xmlChar,
1802) -> *mut _xmlAttr {
1803 crate::xml::tree::set_ns_prop(node, ns, name, value)
1804}
1805
1806#[no_mangle]
1816pub unsafe extern "C" fn xmlRemoveProp(attr: *mut _xmlAttr) -> c_int {
1817 crate::xml::tree::remove_prop(attr)
1818}
1819
1820#[no_mangle]
1830pub unsafe extern "C" fn xmlHasProp(node: *const _xmlNode, name: *const xmlChar) -> *mut _xmlAttr {
1831 crate::xml::tree::has_prop(node as *mut _xmlNode, name)
1832}
1833
1834#[no_mangle]
1843pub unsafe extern "C" fn xmlHasNsProp(
1844 node: *const _xmlNode,
1845 name: *const xmlChar,
1846 nameSpace: *const xmlChar,
1847) -> *mut _xmlAttr {
1848 crate::xml::tree::has_ns_prop(node as *mut _xmlNode, name, nameSpace)
1849}
1850
1851#[no_mangle]
1861pub unsafe extern "C" fn xmlUnsetProp(node: *mut _xmlNode, name: *const xmlChar) -> c_int {
1862 crate::xml::tree::unset_prop(node, name)
1863}
1864
1865#[no_mangle]
1874pub unsafe extern "C" fn xmlUnsetNsProp(
1875 node: *mut _xmlNode,
1876 name: *const xmlChar,
1877 nameSpace: *const xmlChar,
1878) -> c_int {
1879 crate::xml::tree::unset_ns_prop(node, name, nameSpace)
1880}
1881
1882#[no_mangle]
1890pub unsafe extern "C" fn xmlFirstElementChild(parent: *mut _xmlNode) -> *mut _xmlNode {
1891 crate::xml::tree::first_element_child(parent)
1892}
1893
1894#[no_mangle]
1896pub unsafe extern "C" fn xmlLastElementChild(parent: *mut _xmlNode) -> *mut _xmlNode {
1897 crate::xml::tree::last_element_child(parent)
1898}
1899
1900#[no_mangle]
1902pub unsafe extern "C" fn xmlNextElementSibling(node: *mut _xmlNode) -> *mut _xmlNode {
1903 crate::xml::tree::next_element_sibling(node)
1904}
1905
1906#[no_mangle]
1908pub unsafe extern "C" fn xmlPreviousElementSibling(node: *mut _xmlNode) -> *mut _xmlNode {
1909 crate::xml::tree::previous_element_sibling(node)
1910}
1911
1912#[no_mangle]
1920pub unsafe extern "C" fn xmlChildElementCount(parent: *mut _xmlNode) -> c_ulong {
1921 crate::xml::tree::child_element_count(parent)
1922}
1923
1924#[no_mangle]
1932pub unsafe extern "C" fn xmlTextConcat(
1933 node: *mut _xmlNode,
1934 content: *const xmlChar,
1935 len: c_int,
1936) -> c_int {
1937 crate::xml::tree::text_concat(node, content, len)
1938}
1939
1940#[no_mangle]
1948pub unsafe extern "C" fn xmlTextMerge(
1949 first: *mut _xmlNode,
1950 second: *mut _xmlNode,
1951) -> *mut _xmlNode {
1952 crate::xml::tree::text_merge(first, second)
1953}
1954
1955#[no_mangle]
1963pub const extern "C" fn xmlGetIntSubset(doc: *const _xmlDoc) -> *mut _xmlDtd {
1964 crate::xml::tree::get_int_subset(doc)
1965}
1966
1967#[no_mangle]
1976pub unsafe extern "C" fn xmlNewDtd(
1977 doc: *mut _xmlDoc,
1978 name: *const xmlChar,
1979 ExternalID: *const xmlChar,
1980 SystemID: *const xmlChar,
1981) -> *mut _xmlDtd {
1982 crate::xml::tree::new_dtd(doc, name, ExternalID, SystemID)
1983}
1984
1985#[no_mangle]
1995pub unsafe extern "C" fn xmlNewEntity(
1996 doc: *mut _xmlDoc,
1997 name: *const xmlChar,
1998 type_: c_int,
1999 ExternalID: *const xmlChar,
2000 SystemID: *const xmlChar,
2001 content: *const xmlChar,
2002) -> *mut _xmlEntity {
2003 crate::xml::tree::new_entity(doc, name, type_, ExternalID, SystemID, content)
2004}
2005
2006#[no_mangle]
2014pub unsafe extern "C" fn xmlGetDocEntity(
2015 doc: *const _xmlDoc,
2016 name: *const xmlChar,
2017) -> *mut _xmlEntity {
2018 crate::xml::tree::get_doc_entity(doc, name)
2019}
2020
2021#[no_mangle]
2029pub unsafe extern "C" fn xmlGetParameterEntity(
2030 doc: *const _xmlDoc,
2031 name: *const xmlChar,
2032) -> *mut _xmlEntity {
2033 crate::xml::tree::get_parameter_entity(doc, name)
2034}
2035
2036#[no_mangle]
2047pub unsafe extern "C" fn xmlCreateIntSubset(
2048 doc: *mut _xmlDoc,
2049 name: *const xmlChar,
2050 ExternalID: *const xmlChar,
2051 SystemID: *const xmlChar,
2052) -> *mut _xmlDtd {
2053 crate::xml::dtd::create_int_subset(doc, name, ExternalID, SystemID)
2054}
2055
2056#[no_mangle]
2064pub unsafe extern "C" fn xmlFreeDtd(dtd: *mut _xmlDtd) {
2065 crate::xml::dtd::free_dtd(dtd);
2066}
2067
2068#[no_mangle]
2084pub unsafe extern "C" fn xmlAddNotationDecl(
2085 _ctxt: *mut _xmlValidCtxt,
2086 dtd: *mut _xmlDtd,
2087 name: *const xmlChar,
2088 PublicID: *const xmlChar,
2089 SystemID: *const xmlChar,
2090) -> *mut _xmlNotation {
2091 crate::xml::dtd::add_notation_decl(dtd, name, PublicID, SystemID)
2092}
2093
2094#[no_mangle]
2102pub unsafe extern "C" fn xmlGetNotationDecl(
2103 dtd: *mut _xmlDtd,
2104 name: *const xmlChar,
2105) -> *mut _xmlNotation {
2106 crate::xml::dtd::get_notation_decl(dtd, name)
2107}
2108
2109#[no_mangle]
2117pub unsafe extern "C" fn xmlCopyNotation(notation: *mut _xmlNotation) -> *mut _xmlNotation {
2118 crate::xml::dtd::copy_notation(notation)
2119}
2120
2121#[no_mangle]
2129pub unsafe extern "C" fn xmlFreeNotation(notation: *mut _xmlNotation) {
2130 crate::xml::dtd::free_notation(notation);
2131}
2132
2133#[no_mangle]
2147pub unsafe extern "C" fn xmlAddElementDecl(
2148 _ctxt: *mut _xmlValidCtxt,
2149 dtd: *mut _xmlDtd,
2150 name: *const xmlChar,
2151 type_: c_int,
2152 content: *mut _xmlElementContent,
2153) -> *mut _xmlElement {
2154 crate::xml::dtd::add_element_decl(dtd, name, type_, content)
2155}
2156
2157#[no_mangle]
2165pub unsafe extern "C" fn xmlGetElementDecl(
2166 dtd: *mut _xmlDtd,
2167 name: *const xmlChar,
2168) -> *mut _xmlElement {
2169 crate::xml::dtd::get_element_decl(dtd, name)
2170}
2171
2172#[no_mangle]
2180pub unsafe extern "C" fn xmlCopyElement(elem: *mut _xmlElement) -> *mut _xmlElement {
2181 crate::xml::dtd::copy_element(elem)
2182}
2183
2184#[no_mangle]
2192pub unsafe extern "C" fn xmlFreeElement(elem: *mut _xmlElement) {
2193 crate::xml::dtd::free_element(elem);
2194}
2195
2196#[no_mangle]
2215pub unsafe extern "C" fn xmlAddAttributeDecl(
2216 _ctxt: *mut _xmlValidCtxt,
2217 dtd: *mut _xmlDtd,
2218 elem: *mut _xmlElement,
2219 name: *const xmlChar,
2220 ns: *const xmlChar,
2221 type_: c_int,
2222 def: c_int,
2223 defaultValue: *const xmlChar,
2224 tree: *mut _xmlEnumeration,
2225) -> *mut _xmlAttribute {
2226 crate::xml::dtd::add_attribute_decl(dtd, elem, name, ns, type_, def, defaultValue, tree)
2227}
2228
2229#[no_mangle]
2238pub unsafe extern "C" fn xmlGetAttributeDecl(
2239 dtd: *mut _xmlDtd,
2240 elem: *mut _xmlElement,
2241 name: *const xmlChar,
2242 namePrefix: c_int,
2243) -> *mut _xmlAttribute {
2244 crate::xml::dtd::get_attribute_decl(dtd, elem, name, namePrefix)
2245}
2246
2247#[no_mangle]
2255pub unsafe extern "C" fn xmlCopyAttribute(attr: *mut _xmlAttribute) -> *mut _xmlAttribute {
2256 crate::xml::dtd::copy_attribute_decl(attr)
2257}
2258
2259#[no_mangle]
2267pub unsafe extern "C" fn xmlFreeAttribute(attr: *mut _xmlAttribute) {
2268 crate::xml::dtd::free_attribute(attr);
2269}
2270
2271#[no_mangle]
2279pub unsafe extern "C" fn xmlNewElementContent(
2280 name: *const xmlChar,
2281 type_: c_int,
2282) -> *mut _xmlElementContent {
2283 crate::xml::dtd::create_content_model(name, type_)
2284}
2285
2286#[no_mangle]
2294pub unsafe extern "C" fn xmlCopyElementContent(
2295 content: *mut _xmlElementContent,
2296) -> *mut _xmlElementContent {
2297 crate::xml::dtd::copy_content_model(content)
2298}
2299
2300#[no_mangle]
2308pub unsafe extern "C" fn xmlFreeElementContent(cur: *mut _xmlElementContent) {
2309 crate::xml::dtd::free_content_model(cur);
2310}
2311
2312#[no_mangle]
2332pub unsafe extern "C" fn xmlAddEntity(
2333 doc: *mut _xmlDoc,
2334 extSubset: c_int,
2335 name: *const xmlChar,
2336 type_: c_int,
2337 publicId: *const xmlChar,
2338 systemId: *const xmlChar,
2339 content: *const xmlChar,
2340 out: *mut *mut _xmlEntity,
2341) -> c_int {
2342 crate::xml::entities::add_entity_doc(
2343 doc, extSubset, name, type_, publicId, systemId, content, out,
2344 )
2345}
2346
2347#[no_mangle]
2359pub unsafe extern "C" fn xmlAddDocEntity(
2360 doc: *mut _xmlDoc,
2361 name: *const xmlChar,
2362 type_: c_int,
2363 ExternalID: *const xmlChar,
2364 SystemID: *const xmlChar,
2365 content: *const xmlChar,
2366) -> *mut _xmlEntity {
2367 crate::xml::tree::add_doc_entity(doc, name, type_, ExternalID, SystemID, content)
2368}
2369
2370#[no_mangle]
2381pub unsafe extern "C" fn xmlAddDtdEntity(
2382 doc: *mut _xmlDoc,
2383 name: *const xmlChar,
2384 type_: c_int,
2385 ExternalID: *const xmlChar,
2386 SystemID: *const xmlChar,
2387 content: *const xmlChar,
2388) -> *mut _xmlEntity {
2389 crate::xml::tree::add_dtd_entity(doc, name, type_, ExternalID, SystemID, content)
2390}
2391
2392#[no_mangle]
2401pub unsafe extern "C" fn xmlGetDtdEntity(
2402 doc: *mut _xmlDoc,
2403 name: *const xmlChar,
2404) -> *mut _xmlEntity {
2405 crate::xml::tree::get_dtd_entity(doc, name)
2406}
2407
2408#[no_mangle]
2416pub unsafe extern "C" fn xmlGetEntity(doc: *mut _xmlDoc, name: *const xmlChar) -> *mut _xmlEntity {
2417 crate::xml::entities::get_entity(doc, name)
2418}
2419
2420#[no_mangle]
2428pub unsafe extern "C" fn xmlCopyEntity(entity: *mut _xmlEntity) -> *mut _xmlEntity {
2429 crate::xml::entities::copy_entity(entity)
2430}
2431
2432#[no_mangle]
2440pub unsafe extern "C" fn xmlFreeEntity(entity: *mut _xmlEntity) {
2441 crate::xml::entities::free_entity(entity);
2442}
2443
2444#[no_mangle]
2452pub unsafe extern "C" fn xmlEncodeEntitiesReentrant(
2453 doc: *mut _xmlDoc,
2454 input: *const xmlChar,
2455) -> *mut xmlChar {
2456 crate::xml::entities::encode_entities_reentrant(doc, input)
2457}
2458
2459#[no_mangle]
2470pub unsafe extern "C" fn xmlEncodeSpecialChars(
2471 _doc: *const _xmlDoc,
2472 input: *const xmlChar,
2473) -> *mut xmlChar {
2474 if input.is_null() {
2475 return ptr::null_mut();
2476 }
2477 unsafe {
2478 let len = crate::xml::string::xml_strlen(input);
2479 let cap = len * 6 + 1;
2482 let out = crate::abi::allocator::xmlMallocImpl(cap) as *mut xmlChar;
2483 if out.is_null() {
2484 return ptr::null_mut();
2485 }
2486 let mut o = 0usize;
2487 let mut i = 0usize;
2488 while i < len {
2489 let c = *input.add(i);
2490 let rep: &[u8] = match c {
2491 b'<' => b"<",
2492 b'>' => b">",
2493 b'&' => b"&",
2494 b'"' => b""",
2495 b'\r' => b" ",
2496 _ => {
2497 *out.add(o) = c;
2498 o += 1;
2499 i += 1;
2500 continue;
2501 }
2502 };
2503 core::ptr::copy_nonoverlapping(rep.as_ptr(), out.add(o), rep.len());
2504 o += rep.len();
2505 i += 1;
2506 }
2507 *out.add(o) = 0;
2508 out
2509 }
2510}
2511
2512#[no_mangle]
2523pub unsafe extern "C" fn xmlEncodeEntities(
2524 _doc: *mut _xmlDoc,
2525 _input: *const xmlChar,
2526) -> *mut xmlChar {
2527 use core::sync::atomic::{AtomicBool, Ordering};
2528 static WARNED: AtomicBool = AtomicBool::new(false);
2529 if !WARNED.swap(true, Ordering::Relaxed) {
2530 let msg = b"xmlEncodeEntities is deprecated, use xmlEncodeSpecialChars or xmlEncodeEntitiesReentrant\n";
2532 unsafe {
2533 libc::fwrite(
2534 msg.as_ptr() as *const c_void,
2535 1,
2536 msg.len(),
2537 libc::fdopen(2, b"w\0" as *const u8 as *const c_char),
2538 );
2539 }
2540 }
2541 ptr::null_mut()
2542}
2543
2544#[no_mangle]
2552pub extern "C" fn xmlGetLineNo(node: *const _xmlNode) -> c_long {
2553 crate::xml::tree::get_line_no(node)
2554}
2555
2556#[no_mangle]
2568pub unsafe extern "C" fn xmlNodeDump(
2569 buf: *mut _xmlBuffer,
2570 doc: *mut _xmlDoc,
2571 cur: *mut _xmlNode,
2572 level: c_int,
2573 format: c_int,
2574) -> c_int {
2575 if buf.is_null() || cur.is_null() {
2576 return -1;
2577 }
2578 crate::xml::tree::xmlNodeDump(buf, doc, cur, level, format)
2579}
2580
2581#[no_mangle]
2589pub unsafe extern "C" fn xmlDocDump(fp: *mut c_void, doc: *mut _xmlDoc) -> c_int {
2590 if fp.is_null() || doc.is_null() {
2591 return -1;
2592 }
2593 crate::xml::tree::xmlDocDump(fp, doc)
2594}
2595
2596#[no_mangle]
2604pub unsafe extern "C" fn xmlDocDumpFormatMemory(
2605 doc: *mut _xmlDoc,
2606 mem: *mut *mut xmlChar,
2607 size: *mut c_int,
2608 format: c_int,
2609) {
2610 if doc.is_null() || mem.is_null() || size.is_null() {
2611 return;
2612 }
2613 crate::xml::tree::xmlDocDumpFormatMemory(doc, mem, size, format)
2614}
2615
2616#[no_mangle]
2624pub unsafe extern "C" fn xmlDocDumpMemory(
2625 doc: *mut _xmlDoc,
2626 mem: *mut *mut xmlChar,
2627 size: *mut c_int,
2628) {
2629 if doc.is_null() || mem.is_null() || size.is_null() {
2630 return;
2631 }
2632 crate::xml::tree::xmlDocDumpMemory(doc, mem, size)
2633}
2634
2635#[no_mangle]
2643pub unsafe extern "C" fn xmlSaveFile(filename: *const c_char, cur: *mut _xmlDoc) -> c_int {
2644 if filename.is_null() || cur.is_null() {
2645 return -1;
2646 }
2647 crate::xml::tree::xmlSaveFile(filename, cur)
2648}
2649
2650#[no_mangle]
2658pub unsafe extern "C" fn xmlSaveFileEnc(
2659 filename: *const c_char,
2660 cur: *mut _xmlDoc,
2661 encoding: *const c_char,
2662) -> c_int {
2663 if filename.is_null() || cur.is_null() {
2664 return -1;
2665 }
2666 crate::xml::tree::xmlSaveFileEnc(filename, cur, encoding)
2667}
2668
2669#[no_mangle]
2677pub unsafe extern "C" fn xmlSaveFormatFile(
2678 filename: *const c_char,
2679 cur: *mut _xmlDoc,
2680 format: c_int,
2681) -> c_int {
2682 if filename.is_null() || cur.is_null() {
2683 return -1;
2684 }
2685 crate::xml::tree::xmlSaveFormatFile(filename, cur, format)
2686}
2687
2688#[no_mangle]
2696pub unsafe extern "C" fn xmlSaveFormatFileEnc(
2697 filename: *const c_char,
2698 cur: *mut _xmlDoc,
2699 encoding: *const c_char,
2700 format: c_int,
2701) -> c_int {
2702 if filename.is_null() || cur.is_null() {
2703 return -1;
2704 }
2705 crate::xml::tree::xmlSaveFormatFileEnc(filename, cur, encoding, format)
2706}
2707
2708#[no_mangle]
2723pub unsafe extern "C" fn xmlReadDoc(
2724 cur: *const xmlChar,
2725 URL: *const c_char,
2726 encoding: *const c_char,
2727 options: c_int,
2728) -> *mut _xmlDoc {
2729 if cur.is_null() {
2731 return ptr::null_mut();
2732 }
2733 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2734 if ctxt.is_null() {
2735 return ptr::null_mut();
2736 }
2737 let len = crate::xml::string::xml_strlen(cur);
2738 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
2739 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2740 (*ctxt).options = options;
2741 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
2742 let doc = (*ctxt).myDoc;
2743 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2744 return doc;
2745 }
2746 let doc = (*ctxt).myDoc;
2747 if !doc.is_null() {
2748 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
2749 }
2750 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2751 doc
2752}
2753
2754#[no_mangle]
2762pub unsafe extern "C" fn xmlReadFile(
2763 URL: *const c_char,
2764 encoding: *const c_char,
2765 options: c_int,
2766) -> *mut _xmlDoc {
2767 if URL.is_null() {
2769 return ptr::null_mut();
2770 }
2771 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2772 if ctxt.is_null() {
2773 return ptr::null_mut();
2774 }
2775 let input = match crate::xml::parser::helpers::input_from_file(URL) {
2776 Ok(input) => input,
2777 Err(_) => {
2778 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2779 return ptr::null_mut();
2780 }
2781 };
2782 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2783 (*ctxt).options = options;
2784 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
2785 let doc = (*ctxt).myDoc;
2786 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2787 if options & 1 << 0 != 0 {
2791 return doc;
2792 }
2793 if !doc.is_null() {
2794 crate::xml::tree::free_doc(doc);
2795 }
2796 return ptr::null_mut();
2797 }
2798 let doc = (*ctxt).myDoc;
2799 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2800 doc
2801}
2802
2803#[no_mangle]
2812pub unsafe extern "C" fn xmlRecoverDoc(cur: *const xmlChar) -> *mut _xmlDoc {
2813 unsafe { xmlReadDoc(cur, ptr::null(), ptr::null(), 1 << 0) }
2814}
2815
2816#[no_mangle]
2824pub unsafe extern "C" fn xmlRecoverFile(filename: *const c_char) -> *mut _xmlDoc {
2825 unsafe { xmlReadFile(filename, ptr::null(), 1 << 0) }
2826}
2827
2828#[no_mangle]
2836pub unsafe extern "C" fn xmlRecoverMemory(buffer: *const c_char, size: c_int) -> *mut _xmlDoc {
2837 unsafe { xmlReadMemory(buffer, size, ptr::null(), ptr::null(), 1 << 0) }
2838}
2839
2840#[no_mangle]
2849pub unsafe extern "C" fn xmlReadMemory(
2850 buffer: *const c_char,
2851 size: c_int,
2852 URL: *const c_char,
2853 encoding: *const c_char,
2854 options: c_int,
2855) -> *mut _xmlDoc {
2856 if buffer.is_null() || size < 0 {
2860 return ptr::null_mut();
2861 }
2862 if size == c_int::MAX {
2871 return ptr::null_mut();
2872 }
2873 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2874 if ctxt.is_null() {
2875 return ptr::null_mut();
2876 }
2877 let input = crate::xml::parser::helpers::input_from_memory_named(buffer, size, URL);
2880 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2881 crate::abi::exports_parser::apply_options(ctxt, options);
2885 let parsed = crate::xml::parser::helpers::parse_document(ctxt);
2886 let doc = (*ctxt).myDoc;
2887 if !doc.is_null() && !URL.is_null() && (*doc).URL.is_null() {
2890 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
2891 }
2892 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2893 if parsed != 0 {
2894 if options & 1 << 0 != 0 {
2898 return doc;
2899 }
2900 if !doc.is_null() {
2901 crate::xml::tree::free_doc(doc);
2902 }
2903 return ptr::null_mut();
2904 }
2905 doc
2906}
2907
2908#[no_mangle]
2914pub unsafe extern "C" fn xmlLoadCatalogs(catalogs: *const c_char) {
2915 if !catalogs.is_null() {
2916 crate::xml::catalog::load_catalog(catalogs);
2917 }
2918}
2919
2920#[no_mangle]
2926pub unsafe extern "C" fn xmlLoadCatalog(catalogs: *const c_char) -> c_int {
2927 let handle = crate::xml::catalog::load_catalog(catalogs);
2930 if handle.is_null() {
2931 1
2932 } else {
2933 0
2934 }
2935}
2936
2937#[no_mangle]
2945pub unsafe extern "C" fn xmlReadFd(
2946 fd: c_int,
2947 URL: *const c_char,
2948 encoding: *const c_char,
2949 options: c_int,
2950) -> *mut _xmlDoc {
2951 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2953 if ctxt.is_null() {
2954 return ptr::null_mut();
2955 }
2956 let mut buf = Vec::new();
2958 let mut tmp = [0u8; 4096];
2959 loop {
2960 let n = libc::read(fd, tmp.as_mut_ptr() as *mut c_void, tmp.len());
2961 if n <= 0 {
2962 break;
2963 }
2964 buf.extend_from_slice(&tmp[..n as usize]);
2965 }
2966 let input = crate::xml::parser::helpers::input_from_memory(
2967 buf.as_ptr() as *const c_char,
2968 buf.len() as c_int,
2969 );
2970 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2971 (*ctxt).options = options;
2972 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
2973 let doc = (*ctxt).myDoc;
2974 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2975 return doc;
2976 }
2977 let doc = (*ctxt).myDoc;
2978 if !doc.is_null() && !URL.is_null() {
2979 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
2980 }
2981 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2982 doc
2983}
2984
2985#[no_mangle]
2994pub unsafe extern "C" fn xmlReadIO(
2995 ioread: Option<xmlInputReadCallback>,
2996 ioclose: Option<xmlInputCloseCallback>,
2997 ioctx: *mut c_void,
2998 URL: *const c_char,
2999 encoding: *const c_char,
3000 options: c_int,
3001) -> *mut _xmlDoc {
3002 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3004 if ctxt.is_null() {
3005 return ptr::null_mut();
3006 }
3007 let input = crate::xml::parser::helpers::input_from_io(ioread, ioclose, ioctx);
3008 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3009 (*ctxt).options = options;
3010 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
3011 let doc = (*ctxt).myDoc;
3012 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3013 return doc;
3014 }
3015 let doc = (*ctxt).myDoc;
3016 if !doc.is_null() && !URL.is_null() {
3017 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
3018 }
3019 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3020 doc
3021}
3022
3023#[no_mangle]
3031pub unsafe extern "C" fn xmlSAXParseDoc(
3032 sax: *mut _xmlSAXHandler,
3033 cur: *const xmlChar,
3034 recovery: c_int,
3035) -> *mut _xmlDoc {
3036 if cur.is_null() {
3038 return ptr::null_mut();
3039 }
3040 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3041 if ctxt.is_null() {
3042 return ptr::null_mut();
3043 }
3044 if !sax.is_null() {
3045 (*ctxt).sax = sax;
3046 (*ctxt).userData = (*ctxt).sax as *mut c_void;
3047 }
3048 if recovery != 0 {
3049 (*ctxt).recovery = 1;
3050 (*ctxt).options |= 1; }
3052 let len = crate::xml::string::xml_strlen(cur);
3053 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
3054 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3055 crate::xml::parser::helpers::parse_document(ctxt);
3056 let doc = (*ctxt).myDoc;
3057 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3058 doc
3059}
3060
3061#[no_mangle]
3071pub unsafe extern "C" fn xmlSAXParseDocWithData(
3072 sax: *mut _xmlSAXHandler,
3073 cur: *const xmlChar,
3074 recovery: c_int,
3075 data: *mut c_void,
3076) -> *mut _xmlDoc {
3077 if cur.is_null() {
3079 return ptr::null_mut();
3080 }
3081 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3082 if ctxt.is_null() {
3083 return ptr::null_mut();
3084 }
3085 if !sax.is_null() {
3086 (*ctxt).sax = sax;
3087 }
3088 (*ctxt).userData = data;
3089 if recovery != 0 {
3090 (*ctxt).recovery = 1;
3091 (*ctxt).options |= 1; }
3093 let len = crate::xml::string::xml_strlen(cur);
3094 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
3095 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3096 crate::xml::parser::helpers::parse_document(ctxt);
3097 let doc = (*ctxt).myDoc;
3098 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3099 doc
3100}
3101
3102#[no_mangle]
3112pub unsafe extern "C" fn xmlSAXParseFileWithData(
3113 sax: *mut _xmlSAXHandler,
3114 filename: *const c_char,
3115 recovery: c_int,
3116 data: *mut c_void,
3117) -> *mut _xmlDoc {
3118 if filename.is_null() {
3120 return ptr::null_mut();
3121 }
3122 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3123 if ctxt.is_null() {
3124 return ptr::null_mut();
3125 }
3126 if !sax.is_null() {
3127 (*ctxt).sax = sax;
3128 }
3129 (*ctxt).userData = data;
3130 if recovery != 0 {
3131 (*ctxt).recovery = 1;
3132 (*ctxt).options |= 1; }
3134 let input = match crate::xml::parser::helpers::input_from_file(filename) {
3135 Ok(input) => input,
3136 Err(_) => {
3137 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3138 return ptr::null_mut();
3139 }
3140 };
3141 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3142 crate::xml::parser::helpers::parse_document(ctxt);
3143 let doc = (*ctxt).myDoc;
3144 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3145 doc
3146}
3147
3148#[no_mangle]
3158pub unsafe extern "C" fn xmlSAXParseMemoryWithData(
3159 sax: *mut _xmlSAXHandler,
3160 buffer: *const c_char,
3161 size: c_int,
3162 recovery: c_int,
3163 data: *mut c_void,
3164) -> *mut _xmlDoc {
3165 if buffer.is_null() || size <= 0 {
3167 return ptr::null_mut();
3168 }
3169 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3170 if ctxt.is_null() {
3171 return ptr::null_mut();
3172 }
3173 if !sax.is_null() {
3174 (*ctxt).sax = sax;
3175 }
3176 (*ctxt).userData = data;
3177 if recovery != 0 {
3178 (*ctxt).recovery = 1;
3179 (*ctxt).options |= 1; }
3181 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
3182 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3183 crate::xml::parser::helpers::parse_document(ctxt);
3184 let doc = (*ctxt).myDoc;
3185 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3186 doc
3187}
3188
3189#[no_mangle]
3197pub unsafe extern "C" fn xmlSAXParseFile(
3198 sax: *mut _xmlSAXHandler,
3199 filename: *const c_char,
3200 recovery: c_int,
3201) -> *mut _xmlDoc {
3202 if filename.is_null() {
3204 return ptr::null_mut();
3205 }
3206 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3207 if ctxt.is_null() {
3208 return ptr::null_mut();
3209 }
3210 if !sax.is_null() {
3211 (*ctxt).sax = sax;
3212 (*ctxt).userData = (*ctxt).sax as *mut c_void;
3213 }
3214 if recovery != 0 {
3215 (*ctxt).recovery = 1;
3216 (*ctxt).options |= 1;
3217 }
3218 let input = match crate::xml::parser::helpers::input_from_file(filename) {
3219 Ok(input) => input,
3220 Err(_) => {
3221 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3222 return ptr::null_mut();
3223 }
3224 };
3225 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3226 crate::xml::parser::helpers::parse_document(ctxt);
3227 let doc = (*ctxt).myDoc;
3228 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3229 doc
3230}
3231
3232#[no_mangle]
3241pub unsafe extern "C" fn xmlSAXParseMemory(
3242 sax: *mut _xmlSAXHandler,
3243 buffer: *const c_char,
3244 size: c_int,
3245 recovery: c_int,
3246) -> *mut _xmlDoc {
3247 if buffer.is_null() || size <= 0 {
3249 return ptr::null_mut();
3250 }
3251 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3252 if ctxt.is_null() {
3253 return ptr::null_mut();
3254 }
3255 if !sax.is_null() {
3256 (*ctxt).sax = sax;
3257 (*ctxt).userData = (*ctxt).sax as *mut c_void;
3258 }
3259 if recovery != 0 {
3260 (*ctxt).recovery = 1;
3261 (*ctxt).options |= 1;
3262 }
3263 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
3264 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3265 crate::xml::parser::helpers::parse_document(ctxt);
3266 let doc = (*ctxt).myDoc;
3267 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3268 doc
3269}
3270
3271#[no_mangle]
3280pub unsafe extern "C" fn xmlSAXUserParseFile(
3281 sax: *mut _xmlSAXHandler,
3282 user_data: *mut c_void,
3283 filename: *const c_char,
3284) -> c_int {
3285 if filename.is_null() {
3287 return -1;
3288 }
3289 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3290 if ctxt.is_null() {
3291 return -1;
3292 }
3293 if !sax.is_null() {
3294 if unsafe { (*sax).initialized } == XML_SAX2_MAGIC as c_uint {
3298 unsafe {
3299 ptr::copy_nonoverlapping(sax as *const _xmlSAXHandler, (*ctxt).sax, 1);
3300 }
3301 } else {
3302 unsafe {
3303 ptr::copy_nonoverlapping(
3304 sax as *const u8,
3305 (*ctxt).sax as *mut u8,
3306 size_of::<crate::abi::structs::_xmlSAXHandlerV1>(),
3307 );
3308 }
3309 }
3310 }
3311 (*ctxt).userData = if !user_data.is_null() {
3312 user_data
3313 } else {
3314 ctxt as *mut c_void
3315 };
3316 let input = match crate::xml::parser::helpers::input_from_file(filename) {
3317 Ok(input) => input,
3318 Err(_) => {
3319 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3320 return -1;
3321 }
3322 };
3323 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3324 let ret = crate::xml::parser::helpers::parse_document(ctxt);
3325 let ret = if ret == 0 {
3328 0
3329 } else {
3330 let err = unsafe { (*ctxt).errNo };
3331 if err != crate::abi::types::XML_ERR_OK {
3332 err
3333 } else {
3334 -1
3335 }
3336 };
3337 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3338 ret
3339}
3340
3341#[no_mangle]
3350pub unsafe extern "C" fn xmlSAXUserParseMemory(
3351 sax: *mut _xmlSAXHandler,
3352 user_data: *mut c_void,
3353 buffer: *const c_char,
3354 size: c_int,
3355) -> c_int {
3356 if buffer.is_null() || size <= 0 {
3358 return -1;
3359 }
3360 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3361 if ctxt.is_null() {
3362 return -1;
3363 }
3364 if !sax.is_null() {
3365 if unsafe { (*sax).initialized } == XML_SAX2_MAGIC as c_uint {
3372 unsafe {
3373 ptr::copy_nonoverlapping(sax as *const _xmlSAXHandler, (*ctxt).sax, 1);
3374 }
3375 } else {
3376 unsafe {
3377 ptr::copy_nonoverlapping(
3378 sax as *const u8,
3379 (*ctxt).sax as *mut u8,
3380 size_of::<crate::abi::structs::_xmlSAXHandlerV1>(),
3381 );
3382 }
3383 }
3384 }
3385 (*ctxt).userData = if !user_data.is_null() {
3386 user_data
3387 } else {
3388 ctxt as *mut c_void
3389 };
3390 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
3391 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3392 let ret = crate::xml::parser::helpers::parse_document(ctxt);
3393 let ret = if ret == 0 {
3396 0
3397 } else {
3398 let err = unsafe { (*ctxt).errNo };
3399 if err != crate::abi::types::XML_ERR_OK {
3400 err
3401 } else {
3402 -1
3403 }
3404 };
3405 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3406 ret
3407}
3408
3409#[no_mangle]
3417pub unsafe extern "C" fn xmlParseDoc(cur: *const xmlChar) -> *mut _xmlDoc {
3418 if cur.is_null() {
3420 return ptr::null_mut();
3421 }
3422 xmlReadDoc(cur, ptr::null(), ptr::null(), 0)
3423}
3424
3425#[no_mangle]
3433pub unsafe extern "C" fn xmlParseFile(filename: *const c_char) -> *mut _xmlDoc {
3434 if filename.is_null() {
3436 return ptr::null_mut();
3437 }
3438 xmlReadFile(filename, ptr::null(), 0)
3439}
3440
3441#[no_mangle]
3449pub unsafe extern "C" fn xmlParseMemory(buffer: *const c_char, size: c_int) -> *mut _xmlDoc {
3450 if buffer.is_null() || size <= 0 {
3452 return ptr::null_mut();
3453 }
3454 xmlReadMemory(buffer, size, ptr::null(), ptr::null(), 0)
3455}
3456
3457#[no_mangle]
3465pub unsafe extern "C" fn xmlCreateFileParserCtxt(filename: *const c_char) -> *mut _xmlParserCtxt {
3466 if filename.is_null() {
3468 return ptr::null_mut();
3469 }
3470 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3471 if ctxt.is_null() {
3472 return ptr::null_mut();
3473 }
3474 let input = match crate::xml::parser::helpers::input_from_file(filename) {
3475 Ok(input) => input,
3476 Err(_) => {
3477 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3478 return ptr::null_mut();
3479 }
3480 };
3481 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3482 ctxt
3483}
3484
3485#[no_mangle]
3493pub unsafe extern "C" fn xmlCreateDocParserCtxt(cur: *const xmlChar) -> *mut _xmlParserCtxt {
3494 if cur.is_null() {
3496 return ptr::null_mut();
3497 }
3498 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
3499 if ctxt.is_null() {
3500 return ptr::null_mut();
3501 }
3502 let len = crate::xml::string::xml_strlen(cur);
3503 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
3504 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
3505 ctxt
3506}
3507
3508#[no_mangle]
3516pub unsafe extern "C" fn xmlParseDocument(ctxt: *mut _xmlParserCtxt) -> c_int {
3517 if ctxt.is_null() {
3519 return -1;
3520 }
3521 crate::xml::parser::helpers::parse_document(ctxt)
3522}
3523
3524#[no_mangle]
3532pub unsafe extern "C" fn xmlFreeParserCtxt(ctxt: *mut _xmlParserCtxt) {
3533 if ctxt.is_null() {
3534 return;
3535 }
3536 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
3537}
3538
3539#[no_mangle]
3547pub unsafe extern "C" fn xmlCtxtUseOptions(ctxt: *mut _xmlParserCtxt, options: c_int) -> c_int {
3548 if ctxt.is_null() {
3549 return -1;
3550 }
3551 unsafe {
3553 (*ctxt).options = options;
3554 }
3555 0
3556}
3557
3558#[no_mangle]
3567pub unsafe extern "C" fn xmlParseChunk(
3568 ctxt: *mut _xmlParserCtxt,
3569 chunk: *const c_char,
3570 size: c_int,
3571 terminate: c_int,
3572) -> c_int {
3573 if ctxt.is_null() || size < 0 || (chunk.is_null() && size > 0) {
3580 return XML_ERR_ARGUMENT;
3581 }
3582 crate::xml::parser::helpers::parse_chunk(ctxt, chunk, size, terminate)
3583}
3584
3585#[no_mangle]
3593pub unsafe extern "C" fn xmlParserInputBufferCreateMem(
3594 buffer: *const c_char,
3595 size: c_int,
3596 enc: c_int,
3597) -> *mut _xmlParserInputBuffer {
3598 if buffer.is_null() || size <= 0 {
3600 return ptr::null_mut();
3601 }
3602 crate::xml::parser::helpers::alloc_parser_input_buffer()
3603}
3604
3605#[no_mangle]
3613pub unsafe extern "C" fn xmlParserInputBufferCreateFilename(
3614 URI: *const c_char,
3615 enc: c_int,
3616) -> *mut _xmlParserInputBuffer {
3617 if URI.is_null() {
3619 return ptr::null_mut();
3620 }
3621 crate::xml::parser::helpers::alloc_parser_input_buffer()
3622}
3623
3624#[no_mangle]
3634pub unsafe extern "C" fn xmlParserInputBufferCreateIO(
3635 ioread: Option<xmlInputReadCallback>,
3636 ioclose: Option<xmlInputCloseCallback>,
3637 ioctx: *mut c_void,
3638 enc: c_int,
3639) -> *mut _xmlParserInputBuffer {
3640 let buf = crate::xml::parser::helpers::alloc_parser_input_buffer();
3642 if !buf.is_null() {
3643 (*buf).readcallback = ioread;
3644 (*buf).closecallback = ioclose;
3645 (*buf).context = ioctx;
3646 }
3647 buf
3648}
3649
3650#[no_mangle]
3658pub unsafe extern "C" fn xmlFreeParserInputBuffer(buf: *mut _xmlParserInputBuffer) {
3659 if buf.is_null() {
3660 return;
3661 }
3662 crate::xml::parser::helpers::free_parser_input_buffer(buf);
3663}
3664
3665#[no_mangle]
3673pub unsafe extern "C" fn xmlNewInputFromFile(
3674 ctxt: *mut _xmlParserCtxt,
3675 filename: *const c_char,
3676) -> *mut _xmlParserInput {
3677 if filename.is_null() {
3682 return ptr::null_mut();
3683 }
3684 crate::xml::parser::helpers::alloc_parser_input_buffer() as *mut _xmlParserInput
3685}
3686
3687#[no_mangle]
3695pub unsafe extern "C" fn xmlFreeInputStream(input: *mut _xmlParserInput) {
3696 if input.is_null() {
3697 return;
3698 }
3699 crate::xml::parser::helpers::free_parser_input(input);
3700}
3701
3702#[no_mangle]
3716pub unsafe extern "C" fn xmlOutputBufferCreateFilename(
3717 URI: *const c_char,
3718 encoder: *mut c_void,
3719 compression: c_int,
3720) -> *mut _xmlOutputBuffer {
3721 let _ = compression;
3722 if URI.is_null() {
3723 return ptr::null_mut();
3724 }
3725 crate::xml::io::output_buffer_create_filename(
3726 URI,
3727 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3728 0,
3729 )
3730}
3731
3732#[no_mangle]
3741pub unsafe extern "C" fn xmlOutputBufferCreateFd(
3742 fd: c_int,
3743 encoder: *mut c_void,
3744) -> *mut _xmlOutputBuffer {
3745 if fd < 0 {
3746 return ptr::null_mut();
3747 }
3748 crate::xml::io::output_buffer_create_fd(
3749 fd,
3750 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3751 )
3752}
3753
3754#[no_mangle]
3764pub unsafe extern "C" fn xmlOutputBufferCreateIO(
3765 iowrite: Option<xmlOutputWriteCallback>,
3766 ioclose: Option<xmlOutputCloseCallback>,
3767 ioctx: *mut c_void,
3768 encoder: *mut c_void,
3769) -> *mut _xmlOutputBuffer {
3770 crate::xml::io::output_buffer_create_io(
3771 iowrite,
3772 ioclose,
3773 ioctx,
3774 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3775 )
3776}
3777
3778#[no_mangle]
3786pub unsafe extern "C" fn xmlOutputBufferClose(out: *mut _xmlOutputBuffer) -> c_int {
3787 if out.is_null() {
3788 return -1;
3789 }
3790 crate::xml::io::output_buffer_close(out)
3791}
3792
3793#[no_mangle]
3801pub unsafe extern "C" fn xmlOutputBufferFlush(out: *mut _xmlOutputBuffer) -> c_int {
3802 if out.is_null() {
3803 return -1;
3804 }
3805 crate::xml::io::output_buffer_flush(out)
3806}
3807
3808#[no_mangle]
3816pub unsafe extern "C" fn xmlOutputBufferWrite(
3817 out: *mut _xmlOutputBuffer,
3818 len: c_int,
3819 data: *const c_char,
3820) -> c_int {
3821 if out.is_null() || data.is_null() || len <= 0 {
3822 return -1;
3823 }
3824 crate::xml::io::output_buffer_write(out, len, data)
3825}
3826
3827#[no_mangle]
3835pub unsafe extern "C" fn xmlOutputBufferWriteString(
3836 out: *mut _xmlOutputBuffer,
3837 str: *const c_char,
3838) -> c_int {
3839 if str.is_null() {
3840 return 0;
3841 }
3842 unsafe { xmlOutputBufferWrite(out, xmlStrlen(str as *const xmlChar), str) }
3843}
3844
3845#[no_mangle]
3853pub unsafe extern "C" fn xmlAllocOutputBuffer(encoder: *mut c_void) -> *mut _xmlOutputBuffer {
3854 crate::xml::io::output_buffer_create(
3855 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3856 )
3857}
3858
3859#[no_mangle]
3873pub unsafe extern "C" fn xmlOutputBufferCreateBuffer(
3874 buffer: *mut crate::abi::structs::_xmlBuffer,
3875 encoder: *mut c_void,
3876) -> *mut _xmlOutputBuffer {
3877 crate::xml::io::output_buffer_create_buffer(
3878 buffer,
3879 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3880 )
3881}
3882
3883#[no_mangle]
3891pub unsafe extern "C" fn xmlOutputBufferCreateFile(
3892 file: *mut libc::FILE,
3893 encoder: *mut c_void,
3894) -> *mut _xmlOutputBuffer {
3895 crate::xml::io::output_buffer_create_file(
3896 file,
3897 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
3898 )
3899}
3900
3901#[no_mangle]
3907pub unsafe extern "C" fn xmlOutputBufferGetContent(out: *mut _xmlOutputBuffer) -> *const c_char {
3908 crate::xml::io::output_buffer_get_content(out) as *const c_char
3909}
3910
3911#[no_mangle]
3919pub unsafe extern "C" fn xmlOutputBufferGetSize(out: *mut _xmlOutputBuffer) -> usize {
3920 crate::xml::io::output_buffer_get_size(out)
3921}
3922
3923#[no_mangle]
3931pub unsafe extern "C" fn xmlOutputBufferWriteEscape(
3932 out: *mut _xmlOutputBuffer,
3933 str: *const xmlChar,
3934 escaping: Option<xmlCharEncodingOutputFunc>,
3935) -> c_int {
3936 if out.is_null() || str.is_null() {
3937 return -1;
3938 }
3939 crate::xml::io::output_buffer_write_escape(out, str, escaping)
3940}
3941
3942static mut OUTPUT_CREATE_FILENAME_DEFAULT: Option<
3945 unsafe extern "C" fn(
3946 *const c_char,
3947 *mut crate::abi::structs::_xmlCharEncodingHandler,
3948 c_int,
3949 ) -> *mut _xmlOutputBuffer,
3950> = None;
3951
3952#[no_mangle]
3959pub unsafe extern "C" fn xmlOutputBufferCreateFilenameDefault(
3960 func: Option<
3961 unsafe extern "C" fn(
3962 *const c_char,
3963 *mut crate::abi::structs::_xmlCharEncodingHandler,
3964 c_int,
3965 ) -> *mut _xmlOutputBuffer,
3966 >,
3967) -> Option<
3968 unsafe extern "C" fn(
3969 *const c_char,
3970 *mut crate::abi::structs::_xmlCharEncodingHandler,
3971 c_int,
3972 ) -> *mut _xmlOutputBuffer,
3973> {
3974 let old = unsafe { OUTPUT_CREATE_FILENAME_DEFAULT };
3975 if func.is_some() {
3976 unsafe { OUTPUT_CREATE_FILENAME_DEFAULT = func };
3977 }
3978 old
3979}
3980
3981#[no_mangle]
3984pub unsafe extern "C" fn __xmlOutputBufferCreateFilename() -> *mut Option<
3985 unsafe extern "C" fn(
3986 *const c_char,
3987 *mut crate::abi::structs::_xmlCharEncodingHandler,
3988 c_int,
3989 ) -> *mut _xmlOutputBuffer,
3990> {
3991 core::ptr::addr_of_mut!(OUTPUT_CREATE_FILENAME_DEFAULT)
3992}
3993
3994#[no_mangle]
4006pub extern "C" fn xmlDictCreate() -> *mut c_void {
4007 let d = { crate::xml::dictionary::dict_create() as *mut c_void };
4008 if !d.is_null() {
4009 *crate::abi::exports_hash::DICT_REFS
4013 .lock()
4014 .entry(d as usize)
4015 .or_insert(0) = 1;
4016 }
4017 d
4018}
4019
4020#[no_mangle]
4028pub extern "C" fn xmlDictCreateSub(sub: *mut c_void) -> *mut c_void {
4029 let d = unsafe {
4030 crate::xml::dictionary::dict_create_sub(sub as *mut crate::xml::dictionary::Dict)
4031 as *mut c_void
4032 };
4033 if !d.is_null() {
4034 *crate::abi::exports_hash::DICT_REFS
4035 .lock()
4036 .entry(d as usize)
4037 .or_insert(0) = 1;
4038 }
4039 d
4040}
4041
4042#[no_mangle]
4054pub unsafe extern "C" fn xmlDictLookup(
4055 dict: *mut c_void,
4056 name: *const xmlChar,
4057 len: c_int,
4058) -> *const xmlChar {
4059 unsafe {
4060 crate::xml::dictionary::dict_lookup(dict as *mut crate::xml::dictionary::Dict, name, len)
4061 }
4062}
4063
4064#[no_mangle]
4072pub unsafe extern "C" fn xmlDictExists(
4073 dict: *mut c_void,
4074 name: *const xmlChar,
4075 len: c_int,
4076) -> *const xmlChar {
4077 unsafe {
4078 crate::xml::dictionary::dict_exists(dict as *mut crate::xml::dictionary::Dict, name, len)
4079 }
4080}
4081
4082#[no_mangle]
4090pub const extern "C" fn xmlDictSize(dict: *const c_void) -> c_int {
4091 {
4092 crate::xml::dictionary::dict_size(dict as *const crate::xml::dictionary::Dict)
4093 }
4094}
4095
4096#[no_mangle]
4108pub extern "C" fn xmlDictFree(dict: *mut c_void) {
4109 if dict.is_null() {
4110 return;
4111 }
4112 let mut remaining = 0u32;
4113 {
4114 let mut refs = crate::abi::exports_hash::DICT_REFS.lock();
4115 if let Some(r) = refs.get_mut(&(dict as usize)) {
4116 if *r > 0 {
4117 *r -= 1;
4118 }
4119 remaining = *r;
4120 if remaining == 0 {
4121 refs.remove(&(dict as usize));
4122 }
4123 }
4124 }
4125 if remaining == 0 {
4126 unsafe { crate::xml::dictionary::dict_free(dict as *mut crate::xml::dictionary::Dict) };
4127 }
4128}
4129
4130#[no_mangle]
4138pub extern "C" fn xmlDictSetLimit(dict: *mut c_void, limit: usize) -> usize {
4139 {
4140 crate::xml::dictionary::dict_set_limit(dict as *mut crate::xml::dictionary::Dict, limit)
4141 }
4142}
4143
4144#[no_mangle]
4152pub extern "C" fn xmlDictGetUsage(dict: *const c_void) -> usize {
4153 {
4154 crate::xml::dictionary::dict_get_usage(dict as *mut crate::xml::dictionary::Dict)
4155 }
4156}
4157
4158#[no_mangle]
4170pub extern "C" fn xmlHashCreate(size: c_int) -> *mut c_void {
4171 crate::xml::hash::hash_create(size) as *mut c_void
4172}
4173
4174#[no_mangle]
4182pub extern "C" fn xmlHashCreateDict(size: c_int, dict: *mut c_void) -> *mut c_void {
4183 crate::xml::hash::hash_create_dict(size, dict) as *mut c_void
4184}
4185
4186#[no_mangle]
4194pub extern "C" fn xmlHashFree(
4195 table: *mut c_void,
4196 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4197) {
4198 unsafe { crate::xml::hash::hash_free(table as *mut crate::xml::hash::HashTable, f) }
4199}
4200
4201#[no_mangle]
4209pub unsafe extern "C" fn xmlHashAddEntry(
4210 table: *mut c_void,
4211 name: *const xmlChar,
4212 userdata: *mut c_void,
4213) -> c_int {
4214 unsafe {
4215 crate::xml::hash::hash_add_entry(table as *mut crate::xml::hash::HashTable, name, userdata)
4216 }
4217}
4218
4219#[no_mangle]
4228pub unsafe extern "C" fn xmlHashAddEntry2(
4229 table: *mut c_void,
4230 name: *const xmlChar,
4231 name2: *const xmlChar,
4232 userdata: *mut c_void,
4233) -> c_int {
4234 unsafe {
4235 crate::xml::hash::hash_add_entry2(
4236 table as *mut crate::xml::hash::HashTable,
4237 name,
4238 name2,
4239 userdata,
4240 )
4241 }
4242}
4243
4244#[no_mangle]
4253pub unsafe extern "C" fn xmlHashAddEntry3(
4254 table: *mut c_void,
4255 name: *const xmlChar,
4256 name2: *const xmlChar,
4257 name3: *const xmlChar,
4258 userdata: *mut c_void,
4259) -> c_int {
4260 unsafe {
4261 crate::xml::hash::hash_add_entry3(
4262 table as *mut crate::xml::hash::HashTable,
4263 name,
4264 name2,
4265 name3,
4266 userdata,
4267 )
4268 }
4269}
4270
4271#[no_mangle]
4280pub unsafe extern "C" fn xmlHashUpdateEntry(
4281 table: *mut c_void,
4282 name: *const xmlChar,
4283 userdata: *mut c_void,
4284 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4285) -> c_int {
4286 unsafe {
4287 crate::xml::hash::hash_update_entry(
4288 table as *mut crate::xml::hash::HashTable,
4289 name,
4290 userdata,
4291 f,
4292 )
4293 }
4294}
4295
4296#[no_mangle]
4298pub unsafe extern "C" fn xmlHashUpdateEntry2(
4299 table: *mut c_void,
4300 name: *const xmlChar,
4301 name2: *const xmlChar,
4302 userdata: *mut c_void,
4303 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4304) -> c_int {
4305 unsafe {
4306 crate::xml::hash::hash_update_entry2(
4307 table as *mut crate::xml::hash::HashTable,
4308 name,
4309 name2,
4310 userdata,
4311 f,
4312 )
4313 }
4314}
4315
4316#[no_mangle]
4318pub unsafe extern "C" fn xmlHashUpdateEntry3(
4319 table: *mut c_void,
4320 name: *const xmlChar,
4321 name2: *const xmlChar,
4322 name3: *const xmlChar,
4323 userdata: *mut c_void,
4324 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4325) -> c_int {
4326 unsafe {
4327 crate::xml::hash::hash_update_entry3(
4328 table as *mut crate::xml::hash::HashTable,
4329 name,
4330 name2,
4331 name3,
4332 userdata,
4333 f,
4334 )
4335 }
4336}
4337
4338#[no_mangle]
4346pub unsafe extern "C" fn xmlHashLookup(table: *mut c_void, name: *const xmlChar) -> *mut c_void {
4347 unsafe { crate::xml::hash::hash_lookup(table as *mut crate::xml::hash::HashTable, name) }
4348}
4349
4350#[no_mangle]
4352pub unsafe extern "C" fn xmlHashLookup2(
4353 table: *mut c_void,
4354 name: *const xmlChar,
4355 name2: *const xmlChar,
4356) -> *mut c_void {
4357 unsafe {
4358 crate::xml::hash::hash_lookup2(table as *mut crate::xml::hash::HashTable, name, name2)
4359 }
4360}
4361
4362#[no_mangle]
4364pub unsafe extern "C" fn xmlHashLookup3(
4365 table: *mut c_void,
4366 name: *const xmlChar,
4367 name2: *const xmlChar,
4368 name3: *const xmlChar,
4369) -> *mut c_void {
4370 unsafe {
4371 crate::xml::hash::hash_lookup3(
4372 table as *mut crate::xml::hash::HashTable,
4373 name,
4374 name2,
4375 name3,
4376 )
4377 }
4378}
4379
4380#[no_mangle]
4388pub extern "C" fn xmlHashSize(table: *mut c_void) -> c_int {
4389 crate::xml::hash::hash_size(table as *mut crate::xml::hash::HashTable)
4390}
4391
4392#[no_mangle]
4401pub unsafe extern "C" fn xmlHashRemoveEntry(
4402 table: *mut c_void,
4403 name: *const xmlChar,
4404 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4405) -> c_int {
4406 unsafe {
4407 crate::xml::hash::hash_remove_entry(table as *mut crate::xml::hash::HashTable, name, f)
4408 }
4409}
4410
4411#[no_mangle]
4413pub unsafe extern "C" fn xmlHashRemoveEntry2(
4414 table: *mut c_void,
4415 name: *const xmlChar,
4416 name2: *const xmlChar,
4417 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4418) -> c_int {
4419 unsafe {
4420 crate::xml::hash::hash_remove_entry2(
4421 table as *mut crate::xml::hash::HashTable,
4422 name,
4423 name2,
4424 f,
4425 )
4426 }
4427}
4428
4429#[no_mangle]
4431pub unsafe extern "C" fn xmlHashRemoveEntry3(
4432 table: *mut c_void,
4433 name: *const xmlChar,
4434 name2: *const xmlChar,
4435 name3: *const xmlChar,
4436 f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
4437) -> c_int {
4438 unsafe {
4439 crate::xml::hash::hash_remove_entry3(
4440 table as *mut crate::xml::hash::HashTable,
4441 name,
4442 name2,
4443 name3,
4444 f,
4445 )
4446 }
4447}
4448
4449#[no_mangle]
4457pub extern "C" fn xmlHashScan(table: *mut c_void, f: Option<xmlHashScanner>, data: *mut c_void) {
4458 unsafe { crate::xml::hash::hash_scan(table as *mut crate::xml::hash::HashTable, f, data) }
4459}
4460
4461#[no_mangle]
4463pub extern "C" fn xmlHashScanFull(
4464 table: *mut c_void,
4465 f: Option<xmlHashScannerFull>,
4466 data: *mut c_void,
4467) {
4468 unsafe { crate::xml::hash::hash_scan_full(table as *mut crate::xml::hash::HashTable, f, data) }
4469}
4470
4471#[no_mangle]
4479pub extern "C" fn xmlHashCopy(
4480 table: *mut c_void,
4481 f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar) -> *mut c_void>,
4482) -> *mut c_void {
4483 unsafe {
4484 crate::xml::hash::hash_copy(table as *mut crate::xml::hash::HashTable, f) as *mut c_void
4485 }
4486}
4487
4488#[no_mangle]
4501pub extern "C" fn xmlListCreate(
4502 deallocator: Option<unsafe extern "C" fn(*mut c_void)>,
4503 compare: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
4504) -> *mut c_void {
4505 crate::xml::list::list_create(deallocator, compare) as *mut c_void
4506}
4507
4508#[no_mangle]
4516pub extern "C" fn xmlListDelete(list: *mut c_void) {
4517 unsafe { crate::xml::list::list_delete(list as *mut crate::xml::list::List) }
4518}
4519
4520#[no_mangle]
4528pub extern "C" fn xmlListSearch(list: *mut c_void, data: *mut c_void) -> *mut c_void {
4529 unsafe { crate::xml::list::list_search(list as *mut crate::xml::list::List, data) }
4530}
4531
4532#[no_mangle]
4540pub extern "C" fn xmlListWalk(
4541 list: *mut c_void,
4542 walker: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
4543 data: *mut c_void,
4544) {
4545 unsafe { crate::xml::list::list_walk(list as *mut crate::xml::list::List, walker, data) }
4546}
4547
4548#[no_mangle]
4556pub extern "C" fn xmlListPushBack(list: *mut c_void, data: *mut c_void) -> c_int {
4557 unsafe { crate::xml::list::list_push_back(list as *mut crate::xml::list::List, data) }
4558}
4559
4560#[no_mangle]
4568pub extern "C" fn xmlListPushFront(list: *mut c_void, data: *mut c_void) -> c_int {
4569 unsafe { crate::xml::list::list_push_front(list as *mut crate::xml::list::List, data) }
4570}
4571
4572#[no_mangle]
4574pub extern "C" fn xmlListPopBack(list: *mut c_void) {
4575 unsafe { crate::xml::list::list_pop_back(list as *mut crate::xml::list::List) }
4576}
4577
4578#[no_mangle]
4580pub extern "C" fn xmlListPopFront(list: *mut c_void) {
4581 unsafe { crate::xml::list::list_pop_front(list as *mut crate::xml::list::List) }
4582}
4583
4584#[no_mangle]
4592pub extern "C" fn xmlListInsert(list: *mut c_void, data: *mut c_void) -> c_int {
4593 unsafe { crate::xml::list::list_insert(list as *mut crate::xml::list::List, data) }
4594}
4595
4596#[no_mangle]
4598pub extern "C" fn xmlListAppend(list: *mut c_void, data: *mut c_void) -> c_int {
4599 unsafe { crate::xml::list::list_append(list as *mut crate::xml::list::List, data) }
4600}
4601
4602#[no_mangle]
4604pub extern "C" fn xmlListRemoveFirst(list: *mut c_void, data: *mut c_void) -> c_int {
4605 unsafe { crate::xml::list::list_remove_first(list as *mut crate::xml::list::List, data) }
4606}
4607
4608#[no_mangle]
4610pub extern "C" fn xmlListRemoveLast(list: *mut c_void, data: *mut c_void) -> c_int {
4611 unsafe { crate::xml::list::list_remove_last(list as *mut crate::xml::list::List, data) }
4612}
4613
4614#[no_mangle]
4616pub extern "C" fn xmlListRemoveAll(list: *mut c_void, data: *mut c_void) -> c_int {
4617 unsafe { crate::xml::list::list_remove_all(list as *mut crate::xml::list::List, data) }
4618}
4619
4620#[no_mangle]
4622pub extern "C" fn xmlListClear(list: *mut c_void) {
4623 unsafe { crate::xml::list::list_clear(list as *mut crate::xml::list::List) }
4624}
4625
4626#[no_mangle]
4634pub extern "C" fn xmlListEmpty(list: *mut c_void) -> c_int {
4635 crate::xml::list::list_empty(list as *mut crate::xml::list::List)
4636}
4637
4638#[no_mangle]
4646pub extern "C" fn xmlListFront(list: *mut c_void) -> *mut c_void {
4647 crate::xml::list::list_front(list as *mut crate::xml::list::List)
4648}
4649
4650#[no_mangle]
4658pub extern "C" fn xmlListBack(list: *mut c_void) -> *mut c_void {
4659 crate::xml::list::list_back(list as *mut crate::xml::list::List)
4660}
4661
4662#[no_mangle]
4670pub extern "C" fn xmlListSize(list: *mut c_void) -> c_int {
4671 crate::xml::list::list_size(list as *mut crate::xml::list::List)
4672}
4673
4674#[no_mangle]
4676pub extern "C" fn xmlListSort(list: *mut c_void) {
4677 unsafe { crate::xml::list::list_sort(list as *mut crate::xml::list::List) }
4678}
4679
4680#[no_mangle]
4682pub extern "C" fn xmlListReverse(list: *mut c_void) {
4683 unsafe { crate::xml::list::list_reverse(list as *mut crate::xml::list::List) }
4684}
4685
4686#[no_mangle]
4688pub extern "C" fn xmlListReverseSplice(list: *mut c_void, list2: *mut c_void) {
4689 unsafe {
4690 crate::xml::list::list_reverse_splice(
4691 list as *mut crate::xml::list::List,
4692 list2 as *mut crate::xml::list::List,
4693 )
4694 }
4695}
4696
4697#[no_mangle]
4699pub extern "C" fn xmlListMerge(list: *mut c_void, list2: *mut c_void) {
4700 unsafe {
4701 crate::xml::list::list_merge(
4702 list as *mut crate::xml::list::List,
4703 list2 as *mut crate::xml::list::List,
4704 )
4705 }
4706}
4707#[no_mangle]
4715pub unsafe extern "C" fn xmlListEnd(l: *mut c_void) -> *mut c_void {
4716 crate::xml::list::list_end(l as *mut crate::xml::list::List)
4717}
4718
4719#[no_mangle]
4727pub unsafe extern "C" fn xmlListReverseSearch(l: *mut c_void, data: *mut c_void) -> *mut c_void {
4728 crate::xml::list::list_reverse_search(l as *mut crate::xml::list::List, data)
4729}
4730
4731#[no_mangle]
4739pub unsafe extern "C" fn xmlListReverseWalk(
4740 l: *mut c_void,
4741 walker: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
4742 data: *mut c_void,
4743) {
4744 crate::xml::list::list_reverse_walk(l as *mut crate::xml::list::List, walker, data)
4745}
4746
4747#[no_mangle]
4755pub unsafe extern "C" fn xmlListDup(l: *mut c_void) -> *mut c_void {
4756 crate::xml::list::list_dup(l as *mut crate::xml::list::List) as *mut c_void
4757}
4758
4759#[no_mangle]
4770pub unsafe extern "C" fn xmlListCopy(cur: *mut c_void, old: *mut c_void) -> c_int {
4771 crate::xml::list::list_copy(
4772 cur as *mut crate::xml::list::List,
4773 old as *mut crate::xml::list::List,
4774 )
4775}
4776
4777#[no_mangle]
4785pub unsafe extern "C" fn xmlLinkGetData(lk: *mut c_void) -> *mut c_void {
4786 crate::xml::list::link_get_data(lk)
4787}
4788
4789#[no_mangle]
4801pub extern "C" fn xmlBufferCreate() -> *mut _xmlBuffer {
4802 unsafe { xml_buffer_create_upstream(256) }
4807}
4808
4809#[no_mangle]
4822pub extern "C" fn xmlBufferCreateSize(size: usize) -> *mut _xmlBuffer {
4823 if size >= c_int::MAX as usize {
4827 return ptr::null_mut();
4828 }
4829 unsafe { xml_buffer_create_upstream(size) }
4830}
4831
4832unsafe fn xml_buffer_create_upstream(size: usize) -> *mut _xmlBuffer {
4841 let ret = unsafe { xmlMallocImpl(size_of::<_xmlBuffer>()) as *mut _xmlBuffer };
4842 if ret.is_null() {
4843 return ptr::null_mut();
4844 }
4845 let sz = if size != 0 { size + 1 } else { 0 };
4846 unsafe {
4847 if sz != 0 {
4848 let content = xmlMallocImpl(sz) as *mut xmlChar;
4849 if content.is_null() {
4850 xmlFreeImpl(ret as *mut c_void);
4851 return ptr::null_mut();
4852 }
4853 *content = 0;
4854 (*ret).content = content;
4855 (*ret).contentIO = content;
4856 } else {
4857 (*ret).content = ptr::null_mut();
4858 (*ret).contentIO = ptr::null_mut();
4859 }
4860 (*ret).use_ = 0;
4861 (*ret).size = sz as c_uint;
4862 (*ret).alloc = crate::abi::types::xmlBufferAllocationScheme::XML_BUFFER_ALLOC_IO as c_int;
4863 }
4864 ret
4865}
4866
4867#[no_mangle]
4875pub extern "C" fn xmlBufferCreateStatic(mem: *mut c_void, size: usize) -> *mut _xmlBuffer {
4876 if mem.is_null() || size == 0 {
4877 return ptr::null_mut();
4878 }
4879 crate::xml::io::buf_create_static(mem as *const xmlChar, size as c_int)
4880}
4881
4882#[no_mangle]
4890pub extern "C" fn xmlBufferFree(buf: *mut _xmlBuffer) {
4891 crate::xml::io::buf_free(buf)
4892}
4893
4894#[no_mangle]
4902pub extern "C" fn xmlBufferEmpty(buf: *mut _xmlBuffer) {
4903 if buf.is_null() {
4904 return;
4905 }
4906 unsafe {
4907 if !(*buf).content.is_null() {
4908 *(*buf).content = 0;
4909 }
4910 (*buf).use_ = 0;
4911 }
4912}
4913
4914#[no_mangle]
4922pub extern "C" fn xmlBufferContent(buf: *const _xmlBuffer) -> *mut xmlChar {
4923 crate::xml::io::buf_content(buf as *mut _xmlBuffer)
4924}
4925
4926#[no_mangle]
4934pub extern "C" fn xmlBufferLength(buf: *const _xmlBuffer) -> c_int {
4935 crate::xml::io::buf_length(buf as *mut _xmlBuffer)
4936}
4937
4938#[no_mangle]
4946pub unsafe extern "C" fn xmlBufferAdd(
4947 buf: *mut _xmlBuffer,
4948 str: *const xmlChar,
4949 len: c_int,
4950) -> c_int {
4951 crate::xml::io::buf_add(buf, str, len)
4952}
4953
4954#[no_mangle]
4962pub unsafe extern "C" fn xmlBufferAddHead(
4963 buf: *mut _xmlBuffer,
4964 str: *const xmlChar,
4965 len: c_int,
4966) -> c_int {
4967 crate::xml::io::buf_add_head(buf, str, len)
4968}
4969
4970#[no_mangle]
4978pub unsafe extern "C" fn xmlBufferCat(buf: *mut _xmlBuffer, str: *const xmlChar) -> c_int {
4979 if str.is_null() {
4980 return -1;
4981 }
4982 let len = crate::xml::string::xml_strlen(str) as c_int;
4983 crate::xml::io::buf_add(buf, str, len)
4984}
4985
4986#[no_mangle]
4995pub extern "C" fn xmlBufferSetAllocationScheme(buf: *mut _xmlBuffer, scheme: c_int) {
4996 if buf.is_null() {
4997 return;
4998 }
4999 unsafe {
5000 (*buf).alloc = scheme;
5001 }
5002}
5003
5004#[no_mangle]
5015pub extern "C" fn xmlBufferShrink(buf: *mut _xmlBuffer, len: c_uint) -> c_int {
5016 if buf.is_null() {
5017 return -1;
5018 }
5019 if len == 0 {
5020 return 0;
5021 }
5022 unsafe {
5023 let b = &mut *buf;
5024 if len > b.use_ {
5025 return -1;
5026 }
5027 let remaining = b.use_ - len;
5028 if remaining > 0 {
5029 core::ptr::copy(b.content.add(len as usize), b.content, remaining as usize);
5030 }
5031 *b.content.add(remaining as usize) = 0;
5032 b.use_ = remaining;
5033 }
5034 len as c_int
5035}
5036
5037#[no_mangle]
5045pub extern "C" fn xmlBufferGrow(buf: *mut _xmlBuffer, len: c_uint) -> c_int {
5046 if buf.is_null() || len == 0 {
5047 return 0;
5048 }
5049 let cur_use = unsafe { (*buf).use_ };
5050 let new_size = cur_use + len + 1;
5051 crate::xml::io::buf_grow(buf, new_size)
5052}
5053
5054#[no_mangle]
5062pub extern "C" fn xmlBufferReserve(buf: *mut _xmlBuffer, len: c_int) -> c_int {
5063 xmlBufferGrow(buf, len as c_uint)
5064}
5065
5066#[no_mangle]
5074pub extern "C" fn xmlBufferDetach(buf: *mut _xmlBuffer) -> *mut xmlChar {
5075 if buf.is_null() {
5076 return ptr::null_mut();
5077 }
5078 unsafe {
5079 let content = (*buf).content;
5080 (*buf).content = ptr::null_mut();
5081 (*buf).use_ = 0;
5082 (*buf).size = 0;
5083 content
5084 }
5085}
5086
5087#[no_mangle]
5099pub extern "C" fn xmlGetCharEncoding(name: *const c_char) -> c_int {
5100 if name.is_null() {
5101 return 0; }
5103 let name_bytes = unsafe {
5104 let len = libc::strlen(name);
5105 core::slice::from_raw_parts(name as *const u8, len)
5106 };
5107 crate::xml::encoding::encoding_from_name(name_bytes) as c_int
5108}
5109
5110#[no_mangle]
5118pub extern "C" fn xmlFindCharEncodingHandler(name: *const c_char) -> *mut c_void {
5119 if name.is_null() {
5120 return ptr::null_mut();
5121 }
5122 crate::xml::encoding::find_encoding_handler(name as *const xmlChar) as *mut c_void
5123}
5124
5125#[no_mangle]
5133pub extern "C" fn xmlCharEncCloseFunc(handler: *mut c_void) -> c_int {
5134 if handler.is_null() {
5135 return -1;
5136 }
5137 unsafe {
5139 let h = handler as *mut crate::abi::structs::_xmlCharEncodingHandler;
5140 if !(*h).name.is_null() {
5141 crate::abi::allocator::xmlFreeImpl((*h).name as *mut c_void);
5142 }
5143 crate::abi::allocator::xmlFreeImpl(handler);
5144 }
5145 0
5146}
5147
5148#[no_mangle]
5158pub unsafe extern "C" fn xmlIsolat1ToUTF8(
5159 out: *mut u8,
5160 outlen: *mut c_int,
5161 input: *const u8,
5162 inlen: *mut c_int,
5163) -> c_int {
5164 const XML_ENC_ERR_SPACE: c_int = -2;
5166 const XML_ENC_ERR_INTERNAL: c_int = -1;
5167 unsafe {
5168 if out.is_null() || input.is_null() || outlen.is_null() || inlen.is_null() {
5169 return XML_ENC_ERR_INTERNAL;
5170 }
5171 let outstart = out;
5172 let instart = input;
5173 let outend = out.add(*outlen as usize);
5174 let inend = input.add(*inlen as usize);
5175 let mut cur = input;
5176 let mut o = out;
5177 while cur < inend {
5178 let c = *cur;
5179 if c < 0x80 {
5180 if o >= outend {
5181 break;
5182 }
5183 *o = c;
5184 o = o.add(1);
5185 } else {
5186 if (outend as usize) - (o as usize) < 2 {
5187 break;
5188 }
5189 *o = (c >> 6) | 0xC0;
5190 *o.add(1) = (c & 0x3F) | 0x80;
5191 o = o.add(2);
5192 }
5193 cur = cur.add(1);
5194 }
5195 let mut ret = XML_ENC_ERR_SPACE;
5196 if cur == inend {
5197 ret = (o as usize - outstart as usize) as c_int;
5198 }
5199 *outlen = (o as usize - outstart as usize) as c_int;
5200 *inlen = (cur as usize - instart as usize) as c_int;
5201 ret
5202 }
5203}
5204
5205#[no_mangle]
5212pub unsafe extern "C" fn xmlUTF8ToIsolat1(
5213 out: *mut u8,
5214 outlen: *mut c_int,
5215 input: *const u8,
5216 inlen: *mut c_int,
5217) -> c_int {
5218 const XML_ENC_ERR_SPACE: c_int = -2;
5219 const XML_ENC_ERR_INTERNAL: c_int = -1;
5220 const XML_ENC_ERR_INPUT: c_int = -3;
5221 const XML_ENC_ERR_SUCCESS: c_int = 0;
5222 unsafe {
5223 if out.is_null() || outlen.is_null() || inlen.is_null() {
5224 return XML_ENC_ERR_INTERNAL;
5225 }
5226 if input.is_null() {
5227 *inlen = 0;
5228 *outlen = 0;
5229 return XML_ENC_ERR_SUCCESS;
5230 }
5231 let outstart = out;
5232 let instart = input;
5233 let outend = out.add(*outlen as usize);
5234 let inend = input.add(*inlen as usize);
5235 let mut cur = input;
5236 let mut o = out;
5237 let mut ret = XML_ENC_ERR_SPACE;
5238 while cur < inend {
5239 if o >= outend {
5240 break;
5241 }
5242 let c = *cur;
5243 if c < 0x80 {
5244 *o = c;
5245 o = o.add(1);
5246 } else if (0xC2..=0xC3).contains(&c) {
5247 if (inend as usize) - (cur as usize) < 2 {
5248 break;
5249 }
5250 cur = cur.add(1);
5251 *o = (c << 6) | (*cur & 0x3F);
5252 o = o.add(1);
5253 } else {
5254 ret = XML_ENC_ERR_INPUT;
5255 break;
5256 }
5257 cur = cur.add(1);
5258 }
5259 if ret != XML_ENC_ERR_INPUT {
5260 ret = (o as usize - outstart as usize) as c_int;
5261 }
5262 *outlen = (o as usize - outstart as usize) as c_int;
5263 *inlen = (cur as usize - instart as usize) as c_int;
5264 ret
5265 }
5266}
5267
5268#[no_mangle]
5276pub extern "C" fn xmlGetCharEncodingName(enc: c_int) -> *const c_char {
5277 if !(-1..=22).contains(&enc) {
5281 return match enc {
5282 23 => c"UTF-16".as_ptr(),
5283 24 => c"HTML".as_ptr(),
5284 31 => c"windows-1252".as_ptr(),
5285 _ => ptr::null(),
5286 };
5287 }
5288 let e: crate::abi::types::xmlCharEncoding = unsafe { core::mem::transmute(enc) };
5289 crate::xml::encoding::xmlGetCharEncodingName(e)
5290}
5291
5292#[no_mangle]
5302pub extern "C" fn xmlParseCharEncoding(name: *const c_char) -> c_int {
5303 crate::xml::encoding::xmlParseCharEncoding(name)
5304}
5305
5306#[no_mangle]
5314pub extern "C" fn xmlAddEncodingAlias(name: *const c_char, alias: *const c_char) -> c_int {
5315 crate::xml::encoding::add_encoding_alias(name, alias)
5316}
5317
5318#[no_mangle]
5326pub extern "C" fn xmlDelEncodingAlias(alias: *const c_char) -> c_int {
5327 crate::xml::encoding::del_encoding_alias(alias)
5328}
5329
5330#[no_mangle]
5338pub extern "C" fn xmlGetEncodingAlias(alias: *const c_char) -> *const c_char {
5339 crate::xml::encoding::get_encoding_alias(alias)
5340}
5341
5342#[no_mangle]
5350pub extern "C" fn xmlCleanupEncodingAliases() {
5351 crate::xml::encoding::cleanup_encoding_aliases();
5352}
5353
5354#[no_mangle]
5363pub extern "C" fn xmlCharEncInFunc(
5364 handler: *mut c_void,
5365 out: *mut c_void,
5366 in_: *mut c_void,
5367) -> c_int {
5368 crate::xml::encoding::xmlCharEncInFunc(
5369 handler as *mut crate::abi::structs::_xmlCharEncodingHandler,
5370 out as *mut crate::abi::structs::_xmlBuffer,
5371 in_ as *mut crate::abi::structs::_xmlBuffer,
5372 )
5373}
5374
5375#[no_mangle]
5384pub extern "C" fn xmlCharEncOutFunc(
5385 handler: *mut c_void,
5386 out: *mut c_void,
5387 in_: *mut c_void,
5388) -> c_int {
5389 crate::xml::encoding::xmlCharEncOutFunc(
5390 handler as *mut crate::abi::structs::_xmlCharEncodingHandler,
5391 out as *mut crate::abi::structs::_xmlBuffer,
5392 in_ as *mut crate::abi::structs::_xmlBuffer,
5393 )
5394}
5395
5396#[no_mangle]
5406pub extern "C" fn xmlNewCharEncodingHandler(
5407 name: *const c_char,
5408 input: crate::abi::callbacks::xmlCharEncodingInputFunc,
5409 output: crate::abi::callbacks::xmlCharEncodingOutputFunc,
5410) -> *mut c_void {
5411 crate::xml::encoding::xmlNewCharEncodingHandler(name, input, output) as *mut c_void
5412}
5413
5414#[no_mangle]
5422pub extern "C" fn xmlInitCharEncodingHandlers() {
5423 crate::xml::encoding::xmlInitCharEncodingHandlers();
5424}
5425
5426#[no_mangle]
5434pub extern "C" fn xmlCleanupCharEncodingHandlers() {
5435 crate::xml::encoding::xmlCleanupCharEncodingHandlers();
5436}
5437
5438#[no_mangle]
5450pub extern "C" fn xmlLookupCharEncodingHandler(enc: c_int, out: *mut *mut c_void) -> c_int {
5451 crate::xml::encoding::xmlLookupCharEncodingHandler(enc, out)
5452}
5453
5454#[no_mangle]
5462pub extern "C" fn xmlGetCharEncodingHandler(enc: c_int) -> *mut c_void {
5463 crate::xml::encoding::xmlGetCharEncodingHandler(enc)
5464}
5465
5466#[no_mangle]
5475pub extern "C" fn xmlOpenCharEncodingHandler(
5476 name: *const c_char,
5477 output: c_int,
5478 out: *mut *mut c_void,
5479) -> c_int {
5480 crate::xml::encoding::xmlOpenCharEncodingHandler(name, output, out)
5481}
5482
5483#[no_mangle]
5494pub extern "C" fn xmlCreateCharEncodingHandler(
5495 name: *const c_char,
5496 flags: c_int,
5497 impl_: Option<crate::abi::callbacks::xmlCharEncConvImpl>,
5498 implCtxt: *mut c_void,
5499 out: *mut *mut c_void,
5500) -> c_int {
5501 crate::xml::encoding::xmlCreateCharEncodingHandler(name, flags, impl_, implCtxt, out)
5502}
5503
5504#[no_mangle]
5515pub extern "C" fn xmlCharEncNewCustomHandler(
5516 name: *const c_char,
5517 input: crate::abi::callbacks::xmlCharEncConvFunc,
5518 output: crate::abi::callbacks::xmlCharEncConvFunc,
5519 ctxtDtor: Option<crate::abi::callbacks::xmlCharEncConvCtxtDtor>,
5520 inputCtxt: *mut c_void,
5521 outputCtxt: *mut c_void,
5522 out: *mut *mut c_void,
5523) -> c_int {
5524 crate::xml::encoding::xmlCharEncNewCustomHandler(
5525 name, input, output, ctxtDtor, inputCtxt, outputCtxt, out,
5526 )
5527}
5528
5529#[no_mangle]
5537pub unsafe extern "C" fn xmlCharEncInput(input: *mut _xmlParserInputBuffer, _to: c_int) -> c_int {
5538 if input.is_null() {
5539 return -1;
5540 }
5541 let handler = (*input).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
5542 if handler.is_null() {
5543 return -1;
5544 }
5545 let raw = (*input).raw as *mut crate::abi::structs::_xmlBuffer;
5546 let buf = (*input).buffer as *mut crate::abi::structs::_xmlBuffer;
5547 if raw.is_null() || buf.is_null() {
5548 return -1;
5549 }
5550 crate::xml::encoding::char_enc_in(handler, buf, raw)
5551}
5552
5553#[no_mangle]
5561pub unsafe extern "C" fn xmlCharEncOutput(output: *mut _xmlOutputBuffer, _to: c_int) -> c_int {
5562 if output.is_null() {
5563 return -1;
5564 }
5565 let handler = (*output).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
5566 if handler.is_null() {
5567 return -1;
5568 }
5569 let buf = (*output).buffer as *mut crate::abi::structs::_xmlBuffer;
5570 let conv = (*output).conv as *mut crate::abi::structs::_xmlBuffer;
5571 if buf.is_null() || conv.is_null() {
5572 return -1;
5573 }
5574 crate::xml::encoding::char_enc_out(handler, conv, buf)
5575}
5576
5577#[no_mangle]
5589pub unsafe extern "C" fn xmlParseURI(str: *const c_char) -> *mut c_void {
5590 crate::xml::uri::xmlParseURI(str)
5591}
5592
5593#[no_mangle]
5601pub unsafe extern "C" fn xmlParseURIRaw(str: *const c_char, raw: c_int) -> *mut c_void {
5602 let _ = raw;
5603 crate::xml::uri::xmlParseURI(str)
5604}
5605
5606#[no_mangle]
5614pub unsafe extern "C" fn xmlFreeURI(uri: *mut c_void) {
5615 crate::xml::uri::xmlFreeURI(uri)
5616}
5617
5618#[no_mangle]
5626pub extern "C" fn xmlCreateURI() -> *mut c_void {
5627 crate::xml::uri::xmlCreateURI()
5628}
5629
5630#[no_mangle]
5638pub unsafe extern "C" fn xmlSaveUri(uri: *mut c_void) -> *mut xmlChar {
5639 crate::xml::uri::xmlSaveUri(uri)
5640}
5641
5642#[no_mangle]
5658pub unsafe extern "C" fn xmlParseURIReference(uri: *mut c_void, str: *const c_char) -> c_int {
5659 crate::xml::uri::xmlParseURIReference(uri, str)
5660}
5661
5662#[no_mangle]
5677pub unsafe extern "C" fn xmlNormalizeURIPath(path: *mut c_char) -> c_int {
5678 crate::xml::uri::xmlNormalizeURIPath(path)
5679}
5680
5681#[no_mangle]
5689pub unsafe extern "C" fn xmlURIEscapeStr(
5690 str: *const xmlChar,
5691 list: *const xmlChar,
5692) -> *mut xmlChar {
5693 crate::xml::uri::xmlURIEscapeStr(str, list)
5694}
5695
5696#[no_mangle]
5704pub unsafe extern "C" fn xmlURIUnescapeString(
5705 str: *const c_char,
5706 len: c_int,
5707 target: *mut c_char,
5708) -> *mut c_char {
5709 crate::xml::uri::xmlURIUnescapeString(str, len, target)
5710}
5711
5712unsafe fn xpath_to_object(val: XPathValue) -> *mut _xmlXPathObject {
5727 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
5728 if obj.is_null() {
5729 return ptr::null_mut();
5730 }
5731 match val {
5732 XPathValue::NodeSet(ns) => {
5733 (*obj).type_ = xmlXPathObjectType::XPATH_NODESET as c_int;
5734 (*obj).nodesetval = ns.to_raw() as *mut c_void;
5735 }
5736 XPathValue::Boolean(b) => {
5737 (*obj).type_ = xmlXPathObjectType::XPATH_BOOLEAN as c_int;
5738 (*obj).boolval = if b { 1 } else { 0 };
5739 }
5740 XPathValue::Number(n) => {
5741 (*obj).type_ = xmlXPathObjectType::XPATH_NUMBER as c_int;
5742 (*obj).floatval = n;
5743 }
5744 XPathValue::String(s) => {
5745 (*obj).type_ = xmlXPathObjectType::XPATH_STRING as c_int;
5746 let bytes = s.as_bytes();
5747 let len = bytes.len();
5748 let buf = xmlMallocImpl(len + 1) as *mut xmlChar;
5749 if !buf.is_null() {
5750 ptr::copy_nonoverlapping(bytes.as_ptr(), buf, len);
5751 *buf.add(len) = 0; }
5753 (*obj).stringval = buf;
5754 }
5755 }
5756 obj
5757}
5758
5759unsafe fn object_to_xpathvalue(obj: *mut _xmlXPathObject) -> XPathValue {
5766 let typ = (*obj).type_;
5767 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
5768 let ns_ptr = (*obj).nodesetval as *mut _xmlNodeSet;
5769 if ns_ptr.is_null() {
5770 return XPathValue::NodeSet(NodeSet::new());
5771 }
5772 let node_nr = (*ns_ptr).nodeNr;
5773 let node_tab = (*ns_ptr).nodeTab;
5774 let mut ns = NodeSet::new();
5775 if !node_tab.is_null() {
5776 for i in 0..node_nr as isize {
5777 let node = *node_tab.add(i as usize);
5778 ns.push(node);
5779 }
5780 }
5781 XPathValue::NodeSet(ns)
5782 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
5783 XPathValue::Boolean((*obj).boolval != 0)
5784 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
5785 XPathValue::Number((*obj).floatval)
5786 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
5787 let s_ptr = (*obj).stringval;
5788 if s_ptr.is_null() {
5789 XPathValue::String(String::new())
5790 } else {
5791 let s = CStr::from_ptr(s_ptr as *const c_char)
5792 .to_string_lossy()
5793 .into_owned();
5794 XPathValue::String(s)
5795 }
5796 } else if typ == xmlXPathObjectType::XPATH_XSLT_TREE as c_int {
5797 let frag_doc = (*obj).nodesetval as *mut _xmlDoc;
5802 if frag_doc.is_null() {
5803 XPathValue::NodeSet(NodeSet::new())
5804 } else {
5805 let mut ns = NodeSet::new();
5806 ns.push(frag_doc as *mut _xmlNode);
5807 XPathValue::NodeSet(ns)
5808 }
5809 } else {
5810 XPathValue::Boolean(false)
5812 }
5813}
5814
5815pub unsafe fn xpath_to_object_pub(val: XPathValue) -> *mut _xmlXPathObject {
5821 xpath_to_object(val)
5822}
5823
5824pub unsafe fn object_to_xpathvalue_pub(obj: *mut _xmlXPathObject) -> XPathValue {
5831 object_to_xpathvalue(obj)
5832}
5833
5834static COMPILED_EXPRS: Lazy<Mutex<HashMap<u64, Box<CompiledExpr>>>> =
5840 Lazy::new(|| Mutex::new(HashMap::new()));
5841static NEXT_COMPILED_KEY: Lazy<Mutex<u64>> = Lazy::new(|| Mutex::new(1));
5842
5843pub(crate) fn xpath_compiled_registry() -> &'static Mutex<HashMap<u64, Box<CompiledExpr>>> {
5846 &COMPILED_EXPRS
5847}
5848
5849type CXPathFunc = unsafe extern "C" fn(*mut c_void, c_int);
5859
5860#[derive(Clone, Copy, PartialEq, Eq, Hash)]
5863struct SendSyncPtr(*mut c_void);
5864unsafe impl Send for SendSyncPtr {}
5865unsafe impl Sync for SendSyncPtr {}
5866
5867static C_FUNCTIONS: Lazy<Mutex<HashMap<(SendSyncPtr, String), CXPathFunc>>> =
5868 Lazy::new(|| Mutex::new(HashMap::new()));
5869
5870pub(crate) fn xpath_cfunc_lookup(extra: *mut c_void, qualified: &str) -> Option<CXPathFunc> {
5874 C_FUNCTIONS
5875 .lock()
5876 .get(&(SendSyncPtr(extra), qualified.to_string()))
5877 .copied()
5878}
5879
5880pub(crate) fn xpath_cfunc_cleanup(extra: *mut c_void) {
5883 C_FUNCTIONS.lock().retain(|(k, _), _| k.0 != extra);
5884}
5885
5886fn c_func_bridge_closure(c_ctxt: SendSyncPtr, qualified: String) -> BoxedXPathFunction {
5891 Box::new(move |_ctx: &mut XPathContext, args: &[XPathValue]| {
5892 let cc = c_ctxt;
5893 unsafe { c_func_call_bridge(cc.0 as *mut _xmlXPathContext, &qualified, args) }
5894 })
5895}
5896
5897pub(crate) unsafe fn call_c_xpath_function(
5907 fnptr: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
5908 c_ctxt: *mut _xmlXPathContext,
5909 args: &[XPathValue],
5910) -> Result<XPathValue, String> {
5911 let func = match fnptr {
5912 Some(f) => f,
5913 None => return Err("XPath: missing C function pointer".to_string()),
5914 };
5915 let pc = crate::xml::xpath::parser_context::new_parser_context(ptr::null(), c_ctxt);
5916 if pc.is_null() {
5917 return Err("XPath: parser-context allocation failure".to_string());
5918 }
5919 let mut push_ok = true;
5920 for v in args {
5921 let obj = xpath_to_object(v.clone());
5922 if obj.is_null() || crate::xml::xpath::parser_context::value_push(pc, obj).is_null() {
5923 push_ok = false;
5924 break;
5925 }
5926 }
5927 let result = if push_ok {
5928 unsafe { func(pc as *mut c_void, args.len() as c_int) };
5931 let ret = crate::xml::xpath::parser_context::value_pop(pc);
5932 if ret.is_null() {
5933 Err("XPath: C function returned no value".to_string())
5934 } else {
5935 let v = object_to_xpathvalue(ret);
5936 unsafe { xmlXPathFreeObject(ret) };
5938 Ok(v)
5939 }
5940 } else {
5941 Err("XPath: failed to push arguments to C function".to_string())
5942 };
5943 unsafe {
5945 loop {
5946 let leftover = crate::xml::xpath::parser_context::value_pop(pc);
5947 if leftover.is_null() {
5948 break;
5949 }
5950 xmlXPathFreeObject(leftover);
5951 }
5952 crate::xml::xpath::parser_context::free_parser_context(pc);
5953 }
5954 result
5955}
5956
5957unsafe fn c_func_call_bridge(
5964 c_ctxt: *mut _xmlXPathContext,
5965 qualified: &str,
5966 args: &[XPathValue],
5967) -> Result<XPathValue, String> {
5968 if c_ctxt.is_null() {
5969 return Err("XPath: null context in C function bridge".to_string());
5970 }
5971 let func = xpath_cfunc_lookup((*c_ctxt).extra, qualified);
5972 if func.is_none() {
5973 return Err(format!("XPath: unknown C function '{}'", qualified));
5974 }
5975 unsafe { call_c_xpath_function(func, c_ctxt, args) }
5976}
5977
5978#[no_mangle]
5991pub unsafe extern "C" fn xmlXPathNewContext(doc: *mut _xmlDoc) -> *mut _xmlXPathContext {
5992 let ctxt = xmlMallocZero(size_of::<_xmlXPathContext>()) as *mut _xmlXPathContext;
5993 if ctxt.is_null() {
5994 return ptr::null_mut();
5995 }
5996
5997 (*ctxt).doc = doc;
5999 (*ctxt).node = ptr::null_mut();
6000 (*ctxt).contextSize = 1;
6001 (*ctxt).proximityPosition = 1;
6002
6003 let mut internal = Box::new(XPathContext::new(doc));
6005 for (name, func) in crate::xml::xpath::functions::core_functions() {
6010 internal.register_function(&name, func);
6011 }
6012 (*ctxt).extra = Box::into_raw(internal) as *mut c_void;
6013
6014 ctxt
6015}
6016
6017#[no_mangle]
6025pub unsafe extern "C" fn xmlXPathFreeContext(ctxt: *mut _xmlXPathContext) {
6026 if ctxt.is_null() {
6027 return;
6028 }
6029 if !(*ctxt).extra.is_null() {
6031 let _ = Box::from_raw((*ctxt).extra as *mut XPathContext);
6032 (*ctxt).extra = ptr::null_mut();
6033 }
6034 if !(*ctxt).nsHash.is_null() {
6036 drop(Box::from_raw(
6037 (*ctxt).nsHash as *mut HashMap<String, CString>,
6038 ));
6039 (*ctxt).nsHash = ptr::null_mut();
6040 }
6041 xmlFreeImpl(ctxt as *mut c_void);
6043}
6044
6045#[no_mangle]
6054pub unsafe extern "C" fn xmlXPathEvalExpression(
6055 str_: *const xmlChar,
6056 ctxt: *mut _xmlXPathContext,
6057) -> *mut _xmlXPathObject {
6058 if str_.is_null() || ctxt.is_null() {
6059 return ptr::null_mut();
6060 }
6061 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
6062 Ok(s) => s,
6063 Err(_) => return ptr::null_mut(),
6064 };
6065 let internal = (*ctxt).extra as *mut XPathContext;
6066 if internal.is_null() {
6067 return ptr::null_mut();
6068 }
6069 let internal = &mut *internal;
6070 internal.clear_error();
6073
6074 match crate::xml::xpath::evaluate_str(expr_str, internal) {
6075 Some(val) => xpath_to_object(val),
6076 None => {
6077 if internal.error.is_none() {
6082 internal.set_error("Invalid expression");
6083 }
6084 ptr::null_mut()
6085 }
6086 }
6087}
6088
6089#[no_mangle]
6097pub unsafe extern "C" fn xmlXPathEval(
6098 str_: *const xmlChar,
6099 ctxt: *mut _xmlXPathContext,
6100) -> *mut _xmlXPathObject {
6101 xmlXPathEvalExpression(str_, ctxt)
6102}
6103
6104#[no_mangle]
6115pub unsafe extern "C" fn xmlXPathFreeObject(obj: *mut _xmlXPathObject) {
6116 if obj.is_null() {
6117 return;
6118 }
6119 let typ = (*obj).type_;
6120 if typ == xmlXPathObjectType::XPATH_STRING as c_int && !(*obj).stringval.is_null() {
6122 xmlFreeImpl((*obj).stringval as *mut c_void);
6123 (*obj).stringval = ptr::null_mut();
6124 }
6125 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
6127 let ns = (*obj).nodesetval as *mut _xmlNodeSet;
6128 if !ns.is_null() {
6129 if !(*ns).nodeTab.is_null() {
6130 xmlFreeImpl((*ns).nodeTab as *mut c_void);
6131 }
6132 xmlFreeImpl(ns as *mut c_void);
6133 }
6134 (*obj).nodesetval = ptr::null_mut();
6135 }
6136 xmlFreeImpl(obj as *mut c_void);
6137}
6138
6139#[no_mangle]
6151pub unsafe extern "C" fn xmlXPathObjectCopy(val: *mut _xmlXPathObject) -> *mut _xmlXPathObject {
6152 if val.is_null() {
6153 return ptr::null_mut();
6154 }
6155 let typ = (*val).type_;
6156 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
6157 if obj.is_null() {
6158 return ptr::null_mut();
6159 }
6160 (*obj).type_ = typ;
6161 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
6162 let src_ns = (*val).nodesetval as *mut _xmlNodeSet;
6163 if !src_ns.is_null() {
6164 let nr = (*src_ns).nodeNr;
6165 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
6166 if ns.is_null() {
6167 xmlFreeImpl(obj as *mut c_void);
6168 return ptr::null_mut();
6169 }
6170 (*ns).nodeNr = nr;
6171 (*ns).nodeMax = nr;
6172 if nr > 0 && !(*src_ns).nodeTab.is_null() {
6173 let tab = xmlMallocImpl((nr as usize) * core::mem::size_of::<*mut _xmlNode>())
6174 as *mut *mut _xmlNode;
6175 if tab.is_null() {
6176 xmlFreeImpl(ns as *mut c_void);
6177 xmlFreeImpl(obj as *mut c_void);
6178 return ptr::null_mut();
6179 }
6180 ptr::copy_nonoverlapping((*src_ns).nodeTab, tab, nr as usize);
6181 (*ns).nodeTab = tab;
6182 } else {
6183 (*ns).nodeTab = ptr::null_mut();
6184 }
6185 (*obj).nodesetval = ns as *mut c_void;
6186 }
6187 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
6188 (*obj).boolval = (*val).boolval;
6189 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
6190 (*obj).floatval = (*val).floatval;
6191 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
6192 let src = (*val).stringval;
6193 if !src.is_null() {
6194 let len = libc::strlen(src as *const libc::c_char);
6195 let buf = xmlMallocImpl(len + 1) as *mut xmlChar;
6196 if !buf.is_null() {
6197 ptr::copy_nonoverlapping(src, buf, len);
6198 *buf.add(len) = 0;
6199 }
6200 (*obj).stringval = buf;
6201 }
6202 }
6203 obj
6204}
6205
6206#[no_mangle]
6216pub unsafe extern "C" fn xmlXPathCastToString(val: *mut _xmlXPathObject) -> *mut xmlChar {
6217 if val.is_null() {
6218 return ptr::null_mut();
6219 }
6220 let typ = (*val).type_;
6221 let mut result: Vec<u8> = Vec::new();
6222 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
6223 if !(*val).stringval.is_null() {
6224 let len = libc::strlen((*val).stringval as *const libc::c_char);
6225 result.extend_from_slice(core::slice::from_raw_parts((*val).stringval, len));
6226 }
6227 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
6228 let n = (*val).floatval;
6234 result.extend_from_slice(xml_number_to_string(n).as_bytes());
6235 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
6236 result.extend_from_slice(if (*val).boolval != 0 {
6237 b"true"
6238 } else {
6239 b"false"
6240 });
6241 } else if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
6242 let ns = (*val).nodesetval as *mut _xmlNodeSet;
6245 if !ns.is_null() && (*ns).nodeNr > 0 && !(*ns).nodeTab.is_null() {
6246 let node = *(*ns).nodeTab;
6247 if !node.is_null() {
6248 let content = crate::xml::tree::node_get_content(node);
6249 if !content.is_null() {
6250 let len = libc::strlen(content as *const libc::c_char);
6251 result.extend_from_slice(core::slice::from_raw_parts(content, len));
6252 xmlFreeImpl(content as *mut c_void);
6253 }
6254 }
6255 }
6256 }
6257 let buf = xmlMallocImpl(result.len() + 1) as *mut xmlChar;
6259 if buf.is_null() {
6260 return ptr::null_mut();
6261 }
6262 if !result.is_empty() {
6263 ptr::copy_nonoverlapping(result.as_ptr(), buf, result.len());
6264 }
6265 *buf.add(result.len()) = 0;
6266 buf
6267}
6268
6269pub fn xml_number_to_string(n: f64) -> String {
6276 crate::xml::xpath::types::number_to_string(n)
6277}
6278
6279fn xpath_string_eval_number(bytes: &[u8]) -> f64 {
6287 crate::xml::xpath::types::string_bytes_to_number(bytes)
6288}
6289
6290#[no_mangle]
6298pub unsafe extern "C" fn xmlXPathCastStringToNumber(val: *const xmlChar) -> f64 {
6299 if val.is_null() {
6300 return f64::NAN;
6301 }
6302 let len = libc::strlen(val as *const libc::c_char);
6303 let bytes = core::slice::from_raw_parts(val, len);
6304 xpath_string_eval_number(bytes)
6305}
6306
6307#[no_mangle]
6321pub unsafe extern "C" fn xmlXPathCmpNodes(node1: *mut _xmlNode, node2: *mut _xmlNode) -> c_int {
6322 if node1.is_null() || node2.is_null() {
6323 return -2;
6324 }
6325 if node1 == node2 {
6326 return 0;
6327 }
6328 let mut chain1: Vec<*mut _xmlNode> = Vec::new();
6330 let mut chain2: Vec<*mut _xmlNode> = Vec::new();
6331 let mut n = node1;
6332 while !n.is_null() {
6333 chain1.push(n);
6334 n = (*n).parent;
6335 }
6336 let mut n = node2;
6337 while !n.is_null() {
6338 chain2.push(n);
6339 n = (*n).parent;
6340 }
6341 if chain1[chain1.len() - 1] != chain2[chain2.len() - 1] {
6343 return -2;
6344 }
6345 let mut i = chain1.len();
6347 let mut j = chain2.len();
6348 while i > 0 && j > 0 && chain1[i - 1] == chain2[j - 1] {
6349 i -= 1;
6350 j -= 1;
6351 }
6352 if i == 0 {
6354 return 1;
6355 }
6356 if j == 0 {
6358 return -1;
6359 }
6360 let mut a = chain1[i - 1];
6362 let mut b = chain2[j - 1];
6363 while !a.is_null() && !b.is_null() {
6365 let pa = (*a).parent;
6366 let pb = (*b).parent;
6367 if pa == pb {
6368 break;
6369 }
6370 a = pa;
6371 b = pb;
6372 }
6373 let parent = (*a).parent;
6375 let mut child = if parent.is_null() {
6376 ptr::null_mut()
6377 } else {
6378 (*parent).children
6379 };
6380 while !child.is_null() {
6381 if child == a {
6382 return 1; }
6384 if child == b {
6385 return -1; }
6387 child = (*child).next;
6388 }
6389 0
6390}
6391
6392#[no_mangle]
6402pub unsafe extern "C" fn xmlXPathNodeSetCreate(val: *mut _xmlNode) -> *mut _xmlNodeSet {
6403 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
6404 if ns.is_null() {
6405 return ptr::null_mut();
6406 }
6407 if val.is_null() {
6408 return ns;
6409 }
6410 let tab = xmlMallocImpl(core::mem::size_of::<*mut _xmlNode>()) as *mut *mut _xmlNode;
6411 if tab.is_null() {
6412 xmlFreeImpl(ns as *mut c_void);
6413 return ptr::null_mut();
6414 }
6415 *tab = val;
6416 (*ns).nodeTab = tab;
6417 (*ns).nodeNr = 1;
6418 (*ns).nodeMax = 1;
6419 ns
6420}
6421
6422#[no_mangle]
6434pub unsafe extern "C" fn xmlXPathFreeNodeSet(ns: *mut _xmlNodeSet) {
6435 if ns.is_null() {
6436 return;
6437 }
6438 if !(*ns).nodeTab.is_null() {
6439 xmlFreeImpl((*ns).nodeTab as *mut c_void);
6440 (*ns).nodeTab = ptr::null_mut();
6441 }
6442 (*ns).nodeNr = 0;
6443 (*ns).nodeMax = 0;
6444 xmlFreeImpl(ns as *mut c_void);
6445}
6446
6447#[no_mangle]
6458pub unsafe extern "C" fn xmlXPathCompile(str_: *const xmlChar) -> *mut c_void {
6459 if str_.is_null() {
6460 return ptr::null_mut();
6461 }
6462 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
6463 Ok(s) => s,
6464 Err(_) => return ptr::null_mut(),
6465 };
6466
6467 match crate::xml::xpath::compile_result(expr_str) {
6468 Ok(compiled) => {
6469 let mut map = COMPILED_EXPRS.lock();
6470 let mut counter = NEXT_COMPILED_KEY.lock();
6471 let key = *counter;
6472 *counter += 1;
6473 map.insert(key, Box::new(compiled));
6474 key as *mut c_void
6475 }
6476 Err(e) => {
6477 let msg_cstr = std::ffi::CString::new("Invalid expression\n").unwrap_or_default();
6482 let expr_cstr = std::ffi::CString::new(expr_str).unwrap_or_default();
6483 let off = e.pos;
6484 let window = if off < 100 && off < expr_str.len() {
6485 Some((expr_str.as_bytes(), off))
6486 } else {
6487 None
6488 };
6489 unsafe {
6490 crate::xml::errors::raise_error_streamed(
6491 ptr::null_mut(),
6492 crate::abi::types::XML_FROM_XPATH,
6493 crate::abi::types::XPATH_EXPR_ERROR,
6494 crate::abi::types::xmlErrorLevel::XML_ERR_ERROR as c_int,
6495 ptr::null(),
6496 0,
6497 0,
6498 expr_cstr.as_ptr(),
6499 ptr::null(),
6500 ptr::null(),
6501 off as c_int,
6502 msg_cstr.as_ptr(),
6503 window,
6504 None,
6505 crate::xml::errors::GenericDelivery::Stream,
6506 None,
6507 );
6508 }
6509 ptr::null_mut()
6510 }
6511 }
6512}
6513
6514#[no_mangle]
6522pub unsafe extern "C" fn xmlXPathFreeCompExpr(comp: *mut c_void) {
6523 if comp.is_null() {
6524 return;
6525 }
6526 let mut map = COMPILED_EXPRS.lock();
6527 map.remove(&(comp as u64));
6528}
6529
6530#[no_mangle]
6539pub unsafe extern "C" fn xmlXPathRegisterNs(
6540 ctxt: *mut _xmlXPathContext,
6541 prefix: *const xmlChar,
6542 ns_uri: *const xmlChar,
6543) -> c_int {
6544 if ctxt.is_null() || prefix.is_null() || ns_uri.is_null() {
6545 return -1;
6546 }
6547 let internal = (*ctxt).extra as *mut XPathContext;
6548 if internal.is_null() {
6549 return -1;
6550 }
6551 let internal = &mut *internal;
6552
6553 let prefix_str = match CStr::from_ptr(prefix as *const c_char).to_str() {
6554 Ok(s) => s,
6555 Err(_) => return -1,
6556 };
6557 let uri_str = match CStr::from_ptr(ns_uri as *const c_char).to_str() {
6558 Ok(s) => s,
6559 Err(_) => return -1,
6560 };
6561
6562 internal.register_namespace(prefix_str, uri_str);
6563
6564 let map: &mut HashMap<String, CString> = if (*ctxt).nsHash.is_null() {
6569 let b: Box<HashMap<String, CString>> = Box::default();
6570 (*ctxt).nsHash = Box::into_raw(b) as *mut c_void;
6571 &mut *((*ctxt).nsHash as *mut HashMap<String, CString>)
6572 } else {
6573 &mut *((*ctxt).nsHash as *mut HashMap<String, CString>)
6574 };
6575 map.insert(
6576 prefix_str.to_string(),
6577 CString::new(uri_str.as_bytes()).unwrap_or_default(),
6578 );
6579 0
6580}
6581
6582#[no_mangle]
6596pub unsafe extern "C" fn xmlXPathRegisterFunc(
6597 ctxt: *mut _xmlXPathContext,
6598 name: *const xmlChar,
6599 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
6600) -> c_int {
6601 if ctxt.is_null() || name.is_null() {
6602 return -1;
6603 }
6604 let internal = (*ctxt).extra as *mut XPathContext;
6605 if internal.is_null() {
6606 return -1;
6607 }
6608 let internal = &mut *internal;
6609
6610 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
6611 Ok(s) => s,
6612 Err(_) => return -1,
6613 };
6614
6615 if let Some(func) = f {
6616 let key = (SendSyncPtr((*ctxt).extra), name_str.to_string());
6618 C_FUNCTIONS.lock().insert(key, func);
6619 let c_ctxt = SendSyncPtr(ctxt as *mut c_void);
6622 let name_owned = name_str.to_string();
6623 internal.register_function(name_str, c_func_bridge_closure(c_ctxt, name_owned));
6624 }
6625 0
6626}
6627
6628#[no_mangle]
6638pub unsafe extern "C" fn xmlXPathRegisterFuncNS(
6639 ctxt: *mut _xmlXPathContext,
6640 name: *const xmlChar,
6641 ns_uri: *const xmlChar,
6642 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
6643) -> c_int {
6644 if ctxt.is_null() || name.is_null() {
6645 return -1;
6646 }
6647 let internal = (*ctxt).extra as *mut XPathContext;
6648 if internal.is_null() {
6649 return -1;
6650 }
6651 let internal = &mut *internal;
6652
6653 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
6654 Ok(s) => s,
6655 Err(_) => return -1,
6656 };
6657 let ns_str = if ns_uri.is_null() {
6658 String::new()
6659 } else {
6660 match CStr::from_ptr(ns_uri as *const c_char).to_str() {
6661 Ok(s) => s.to_string(),
6662 Err(_) => return -1,
6663 }
6664 };
6665
6666 let qualified = if ns_str.is_empty() {
6668 name_str.to_string()
6669 } else {
6670 format!("{{{}}}{}", ns_str, name_str)
6671 };
6672
6673 if let Some(func) = f {
6674 let key = (SendSyncPtr((*ctxt).extra), qualified.clone());
6675 C_FUNCTIONS.lock().insert(key, func);
6676 let c_ctxt = SendSyncPtr(ctxt as *mut c_void);
6677 let qualified_owned = qualified.clone();
6678 internal.register_function(&qualified, c_func_bridge_closure(c_ctxt, qualified_owned));
6679 }
6680 0
6681}
6682
6683#[no_mangle]
6692pub unsafe extern "C" fn xmlXPathRegisterVariable(
6693 ctxt: *mut _xmlXPathContext,
6694 name: *const xmlChar,
6695 value: *mut _xmlXPathObject,
6696) -> c_int {
6697 if ctxt.is_null() || name.is_null() || value.is_null() {
6698 return -1;
6699 }
6700 let internal = (*ctxt).extra as *mut XPathContext;
6701 if internal.is_null() {
6702 return -1;
6703 }
6704 let internal = &mut *internal;
6705
6706 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
6707 Ok(s) => s,
6708 Err(_) => return -1,
6709 };
6710
6711 let xpath_val = object_to_xpathvalue(value);
6712 internal.register_variable(name_str, xpath_val);
6713 0
6714}
6715
6716#[no_mangle]
6724pub unsafe extern "C" fn xmlXPathNewNodeSet(val: *mut _xmlNode) -> *mut _xmlXPathObject {
6725 let ns = if val.is_null() {
6726 NodeSet::new()
6727 } else {
6728 NodeSet::singleton(val)
6729 };
6730 xpath_to_object(XPathValue::NodeSet(ns))
6731}
6732
6733#[no_mangle]
6741pub unsafe extern "C" fn xmlXPathNewCString(val: *const xmlChar) -> *mut _xmlXPathObject {
6742 if val.is_null() {
6743 return xpath_to_object(XPathValue::String(String::new()));
6744 }
6745 let s = match CStr::from_ptr(val as *const c_char).to_str() {
6746 Ok(s) => s.to_string(),
6747 Err(_) => return ptr::null_mut(),
6748 };
6749 xpath_to_object(XPathValue::String(s))
6750}
6751
6752#[no_mangle]
6760pub extern "C" fn xmlXPathNewFloat(val: f64) -> *mut _xmlXPathObject {
6761 unsafe { xpath_to_object(XPathValue::Number(val)) }
6762}
6763
6764#[no_mangle]
6772pub extern "C" fn xmlXPathNewBoolean(val: c_int) -> *mut _xmlXPathObject {
6773 unsafe { xpath_to_object(XPathValue::Boolean(val != 0)) }
6774}
6775
6776#[no_mangle]
6790pub unsafe extern "C" fn xmlXPtrEval(expr: *const c_char, doc: *mut _xmlDoc) -> *mut _xmlNode {
6791 crate::xml::xpointer::xmlXPtrEval(expr, doc)
6792}
6793
6794#[no_mangle]
6806pub unsafe extern "C" fn xmlXIncludeProcess(doc: *mut _xmlDoc) -> c_int {
6807 crate::xml::xinclude::xinclude_process(doc)
6808}
6809
6810#[no_mangle]
6818pub unsafe extern "C" fn xmlXIncludeProcessFlags(doc: *mut _xmlDoc, flags: c_int) -> c_int {
6819 crate::xml::xinclude::xinclude_process_flags(doc, flags)
6820}
6821
6822#[no_mangle]
6834pub extern "C" fn xmlCatalogLoad(catalogs: *const c_char) -> *mut c_void {
6835 if catalogs.is_null() {
6836 return ptr::null_mut();
6837 }
6838 crate::xml::catalog::load_catalog(catalogs)
6839}
6840
6841#[no_mangle]
6849pub unsafe extern "C" fn xmlCatalogResolvePublic(pubID: *const xmlChar) -> *mut xmlChar {
6850 if pubID.is_null() {
6851 return ptr::null_mut();
6852 }
6853 crate::xml::catalog::resolve_public(pubID)
6854}
6855
6856#[no_mangle]
6864pub unsafe extern "C" fn xmlCatalogResolveSystem(sysID: *const xmlChar) -> *mut xmlChar {
6865 if sysID.is_null() {
6866 return ptr::null_mut();
6867 }
6868 crate::xml::catalog::resolve_system(sysID)
6869}
6870
6871#[no_mangle]
6879pub unsafe extern "C" fn xmlCatalogResolveURI(URI: *const xmlChar) -> *mut xmlChar {
6880 if URI.is_null() {
6881 return ptr::null_mut();
6882 }
6883 crate::xml::catalog::resolve_uri(URI)
6884}
6885
6886#[no_mangle]
6894pub extern "C" fn xmlCatalogSetDefaults(allow: c_int) {
6895 crate::xml::catalog::set_defaults(allow)
6896}
6897
6898#[no_mangle]
6906pub extern "C" fn xmlCatalogGetDefaults() -> c_int {
6907 crate::xml::catalog::get_defaults()
6908}
6909
6910#[no_mangle]
6918pub unsafe extern "C" fn xmlCatalogAdd(
6919 type_: *const xmlChar,
6920 orig: *const xmlChar,
6921 replace: *const xmlChar,
6922) -> c_int {
6923 if type_.is_null() || orig.is_null() || replace.is_null() {
6924 return -1;
6925 }
6926 crate::xml::catalog::add(type_, orig, replace)
6927}
6928
6929#[no_mangle]
6937pub unsafe extern "C" fn xmlCatalogRemove(value: *const xmlChar) -> c_int {
6938 if value.is_null() {
6939 return 0;
6940 }
6941 crate::xml::catalog::remove(value)
6942}
6943
6944#[no_mangle]
6954pub unsafe extern "C" fn xmlCatalogDump(output: *mut c_void) {
6955 if output.is_null() {
6956 return;
6957 }
6958 let doc = crate::xml::catalog::dump_doc();
6959 if doc.is_null() {
6960 return;
6961 }
6962 let mut mem: *mut xmlChar = ptr::null_mut();
6963 let mut size: c_int = 0;
6964 crate::xml::tree::xmlDocDumpFormatMemory(doc, &mut mem, &mut size, 1);
6965 if !mem.is_null() {
6966 libc::fwrite(
6967 mem as *const c_void,
6968 1,
6969 size as usize,
6970 output as *mut libc::FILE,
6971 );
6972 xmlFreeImpl(mem as *mut c_void);
6973 }
6974 crate::xml::tree::free_doc(doc);
6975}
6976
6977#[no_mangle]
6987pub unsafe extern "C" fn xmlCatalogSave(filename: *const c_char) -> c_int {
6988 if filename.is_null() {
6989 return -1;
6990 }
6991 let doc = crate::xml::catalog::dump_doc();
6992 if doc.is_null() {
6993 return -1;
6994 }
6995 let mut mem: *mut xmlChar = ptr::null_mut();
6996 let mut size: c_int = 0;
6997 crate::xml::tree::xmlDocDumpFormatMemory(doc, &mut mem, &mut size, 1);
6998 let mut ret: c_int = -1;
6999 if !mem.is_null() {
7000 let fp = libc::fopen(filename, c"w".as_ptr() as *const c_char);
7001 if !fp.is_null() {
7002 let written = libc::fwrite(mem as *const c_void, 1, size as usize, fp);
7003 ret = if written == size as usize { 0 } else { -1 };
7004 libc::fclose(fp);
7005 }
7006 xmlFreeImpl(mem as *mut c_void);
7007 }
7008 crate::xml::tree::free_doc(doc);
7009 ret
7010}
7011
7012#[no_mangle]
7020pub extern "C" fn xmlCatalogCleanup() {
7021 crate::xml::catalog::cleanup();
7022}
7023
7024#[no_mangle]
7039pub extern "C" fn xmlCatalogConvert() -> c_int {
7040 if !crate::xml::catalog::is_initialized() {
7041 return -1;
7042 }
7043 0
7044}
7045
7046#[no_mangle]
7058pub const unsafe extern "C" fn htmlParseFile(
7059 _filename: *const c_char,
7060 _encoding: *const c_char,
7061) -> *mut _xmlDoc {
7062 ptr::null_mut()
7064}
7065
7066#[no_mangle]
7074pub const unsafe extern "C" fn htmlParseMemory(
7075 _buffer: *const c_char,
7076 _size: c_int,
7077) -> *mut _xmlDoc {
7078 ptr::null_mut()
7080}
7081
7082#[no_mangle]
7090pub const unsafe extern "C" fn htmlParseDoc(
7091 _cur: *const xmlChar,
7092 _encoding: *const c_char,
7093) -> *mut _xmlDoc {
7094 ptr::null_mut()
7096}
7097
7098#[no_mangle]
7107pub const unsafe extern "C" fn htmlCreateFileParserCtxt(
7108 _filename: *const c_char,
7109 _encoding: *const c_char,
7110) -> *mut c_void {
7111 ptr::null_mut()
7113}
7114
7115#[no_mangle]
7123pub extern "C" fn htmlFreeParserCtxt(ctxt: *mut c_void) {
7124 unsafe { crate::xml::html::free_parser_ctxt(ctxt) }
7125}
7126
7127#[no_mangle]
7135pub const extern "C" fn htmlInitParser() {
7136 }
7138
7139#[no_mangle]
7147pub const extern "C" fn htmlCleanupParser() {
7148 }
7150
7151#[no_mangle]
7163pub unsafe extern "C" fn xmlNewValidCtxt() -> *mut _xmlValidCtxt {
7164 crate::xml::validation::new_valid_ctxt()
7165}
7166
7167#[no_mangle]
7175pub unsafe extern "C" fn xmlFreeValidCtxt(ctxt: *mut _xmlValidCtxt) {
7176 crate::xml::validation::free_valid_ctxt(ctxt);
7177}
7178
7179#[no_mangle]
7190pub unsafe extern "C" fn xmlSetValidErrors(
7191 ctxt: *mut _xmlValidCtxt,
7192 err: Option<xmlGenericErrorFunc>,
7193 warn: Option<xmlGenericErrorFunc>,
7194 data: *mut c_void,
7195) {
7196 crate::xml::validation::set_valid_errors(ctxt, err, warn, data);
7197}
7198
7199#[no_mangle]
7207pub unsafe extern "C" fn xmlValidateDocument(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
7208 crate::xml::validation::validate_document(ctxt, doc)
7209}
7210
7211#[no_mangle]
7219pub unsafe extern "C" fn xmlValidateDocumentFinal(
7220 ctxt: *mut _xmlValidCtxt,
7221 doc: *mut _xmlDoc,
7222) -> c_int {
7223 crate::xml::validation::validate_document_final(ctxt, doc)
7224}
7225
7226#[no_mangle]
7236pub unsafe extern "C" fn xmlValidateElement(
7237 ctxt: *mut _xmlValidCtxt,
7238 doc: *mut _xmlDoc,
7239 elem: *mut _xmlNode,
7240) -> c_int {
7241 crate::xml::validation::validate_element(ctxt, doc, elem)
7242}
7243
7244#[no_mangle]
7257pub unsafe extern "C" fn xmlValidateAttributeDecl(
7258 ctxt: *mut _xmlValidCtxt,
7259 doc: *mut _xmlDoc,
7260 attr: *mut _xmlAttribute,
7261) -> c_int {
7262 crate::xml::validation::validate_attribute_decl(ctxt, doc, attr)
7263}
7264
7265#[no_mangle]
7273pub unsafe extern "C" fn xmlValidateAttributeValue(atype: c_int, value: *const xmlChar) -> c_int {
7274 crate::xml::validation::validate_attribute_value(atype, value)
7275}
7276
7277#[no_mangle]
7287pub unsafe extern "C" fn xmlValidateNotationUse(
7288 ctxt: *mut _xmlValidCtxt,
7289 doc: *mut _xmlDoc,
7290 notation_name: *const xmlChar,
7291) -> c_int {
7292 crate::xml::validation::validate_notation_use(ctxt, doc, notation_name)
7293}
7294
7295#[no_mangle]
7306pub unsafe extern "C" fn xmlValidateID(
7307 ctxt: *mut _xmlValidCtxt,
7308 doc: *mut _xmlDoc,
7309 node: *mut _xmlNode,
7310 value: *const xmlChar,
7311) -> c_int {
7312 crate::xml::validation::validate_id(ctxt, doc, node, value)
7313}
7314
7315#[no_mangle]
7325pub unsafe extern "C" fn xmlValidateIDRef(
7326 ctxt: *mut _xmlValidCtxt,
7327 doc: *mut _xmlDoc,
7328 value: *const xmlChar,
7329) -> c_int {
7330 crate::xml::validation::validate_id_ref(ctxt, doc, ptr::null_mut(), value)
7331}
7332
7333#[no_mangle]
7343pub unsafe extern "C" fn xmlValidateIDRefs(
7344 ctxt: *mut _xmlValidCtxt,
7345 doc: *mut _xmlDoc,
7346 value: *const xmlChar,
7347) -> c_int {
7348 crate::xml::validation::validate_id_refs(ctxt, doc, ptr::null_mut(), value)
7349}
7350
7351#[no_mangle]
7361pub unsafe extern "C" fn xmlValidateNCName(value: *const xmlChar, space: c_int) -> c_int {
7362 crate::xml::validation::validate_ncname(value, space)
7363}
7364
7365#[no_mangle]
7373pub unsafe extern "C" fn xmlValidateQName(value: *const xmlChar, space: c_int) -> c_int {
7374 crate::xml::validation::validate_qname(value, space)
7375}
7376
7377#[no_mangle]
7390pub unsafe extern "C" fn xmlValidateName(value: *const xmlChar, space: c_int) -> c_int {
7391 crate::xml::validation::validate_name_space(value, space)
7392}
7393
7394#[no_mangle]
7402pub unsafe extern "C" fn xmlValidateNMToken(value: *const xmlChar, space: c_int) -> c_int {
7403 crate::xml::validation::validate_nmtoken_space(value, space)
7404}
7405
7406#[no_mangle]
7416pub unsafe extern "C" fn xmlValidateNameValue(value: *const xmlChar) -> c_int {
7417 crate::xml::validation::validate_name_value(value)
7418}
7419
7420#[no_mangle]
7429pub unsafe extern "C" fn xmlValidateNamesValue(value: *const xmlChar) -> c_int {
7430 crate::xml::validation::validate_names_value(value)
7431}
7432
7433#[no_mangle]
7441pub unsafe extern "C" fn xmlValidateNmtokenValue(value: *const xmlChar) -> c_int {
7442 crate::xml::validation::validate_nmtoken_value(value)
7443}
7444
7445#[no_mangle]
7453pub unsafe extern "C" fn xmlValidateNmtokensValue(value: *const xmlChar) -> c_int {
7454 crate::xml::validation::validate_nmtokens_value(value)
7455}
7456
7457#[no_mangle]
7468pub unsafe extern "C" fn xmlValidateElementDecl(
7469 ctxt: *mut _xmlValidCtxt,
7470 doc: *mut _xmlDoc,
7471 elem: *mut _xmlElement,
7472) -> c_int {
7473 crate::xml::validation::validate_element_decl(ctxt, doc, elem)
7474}
7475
7476#[no_mangle]
7489pub const unsafe extern "C" fn xmlValidateNotationDecl(
7490 ctxt: *mut _xmlValidCtxt,
7491 doc: *mut _xmlDoc,
7492 nota: *mut _xmlNotation,
7493) -> c_int {
7494 crate::xml::validation::validate_notation_decl(ctxt, doc, nota)
7495}
7496
7497#[no_mangle]
7509pub unsafe extern "C" fn xmlValidateOneAttribute(
7510 ctxt: *mut _xmlValidCtxt,
7511 doc: *mut _xmlDoc,
7512 elem: *mut _xmlNode,
7513 attr: *mut _xmlAttr,
7514 value: *const xmlChar,
7515) -> c_int {
7516 crate::xml::validation::validate_one_attribute(ctxt, doc, elem, attr, value)
7517}
7518
7519#[no_mangle]
7529pub unsafe extern "C" fn xmlValidateOneElement(
7530 ctxt: *mut _xmlValidCtxt,
7531 doc: *mut _xmlDoc,
7532 elem: *mut _xmlNode,
7533) -> c_int {
7534 crate::xml::validation::validate_one_element(ctxt, doc, elem)
7535}
7536
7537#[no_mangle]
7550pub unsafe extern "C" fn xmlValidateOneNamespace(
7551 ctxt: *mut _xmlValidCtxt,
7552 doc: *mut _xmlDoc,
7553 elem: *mut _xmlNode,
7554 prefix: *const xmlChar,
7555 ns: *mut _xmlNs,
7556 value: *const xmlChar,
7557) -> c_int {
7558 crate::xml::validation::validate_one_namespace(ctxt, doc, elem, prefix, ns, value)
7559}
7560
7561#[no_mangle]
7573pub unsafe extern "C" fn xmlValidatePushElement(
7574 ctxt: *mut _xmlValidCtxt,
7575 doc: *mut _xmlDoc,
7576 elem: *mut _xmlNode,
7577 qname: *const xmlChar,
7578) -> c_int {
7579 crate::xml::validation::validate_push_element(ctxt, doc, elem, qname)
7580}
7581
7582#[no_mangle]
7592pub unsafe extern "C" fn xmlValidatePushCData(
7593 ctxt: *mut _xmlValidCtxt,
7594 data: *const xmlChar,
7595 len: c_int,
7596) -> c_int {
7597 crate::xml::validation::validate_push_cdata(ctxt, data, len)
7598}
7599
7600#[no_mangle]
7611pub unsafe extern "C" fn xmlValidatePopElement(
7612 ctxt: *mut _xmlValidCtxt,
7613 doc: *mut _xmlDoc,
7614 elem: *mut _xmlNode,
7615 qname: *const xmlChar,
7616) -> c_int {
7617 crate::xml::validation::validate_pop_element(ctxt, doc, elem, qname)
7618}
7619
7620#[no_mangle]
7629pub unsafe extern "C" fn xmlValidBuildContentModel(
7630 ctxt: *mut _xmlValidCtxt,
7631 elem: *mut _xmlElement,
7632) -> c_int {
7633 crate::xml::validation::validate_build_content_model(ctxt, elem)
7634}
7635
7636#[no_mangle]
7647pub unsafe extern "C" fn xmlAddID(
7648 ctxt: *mut _xmlValidCtxt,
7649 doc: *mut _xmlDoc,
7650 value: *const xmlChar,
7651 attr: *mut _xmlAttr,
7652) -> *mut _xmlID {
7653 crate::xml::validation::add_id(ctxt, doc, value, attr)
7654}
7655
7656#[no_mangle]
7664pub unsafe extern "C" fn xmlRemoveID(doc: *mut _xmlDoc, attr: *mut _xmlAttr) -> c_int {
7665 crate::xml::validation::remove_id(doc, attr)
7666}
7667
7668#[no_mangle]
7679pub unsafe extern "C" fn xmlAddRef(
7680 ctxt: *mut _xmlValidCtxt,
7681 doc: *mut _xmlDoc,
7682 value: *const xmlChar,
7683 attr: *mut _xmlAttr,
7684) -> *mut _xmlRef {
7685 crate::xml::validation::add_ref(ctxt, doc, value, attr)
7686}
7687
7688#[no_mangle]
7696pub unsafe extern "C" fn xmlRemoveRef(doc: *mut _xmlDoc, attr: *mut _xmlAttr) -> c_int {
7697 crate::xml::validation::remove_ref(doc, attr)
7698}
7699
7700#[no_mangle]
7708pub unsafe extern "C" fn xmlAddIDSafe(attr: *mut _xmlAttr, value: *const xmlChar) -> c_int {
7709 crate::xml::validation::add_id_safe(attr, value)
7710}
7711
7712#[no_mangle]
7720pub unsafe extern "C" fn xmlFreeIDTable(table: *mut c_void) {
7721 crate::xml::validation::free_id_table(table as *mut crate::xml::hash::HashTable);
7722}
7723
7724#[no_mangle]
7732pub unsafe extern "C" fn xmlFreeRefTable(table: *mut c_void) {
7733 crate::xml::validation::free_ref_table(table as *mut crate::xml::hash::HashTable);
7734}
7735
7736#[no_mangle]
7744pub unsafe extern "C" fn xmlGetID(doc: *mut _xmlDoc, id: *const xmlChar) -> *mut _xmlAttr {
7745 crate::xml::validation::get_id(doc, id)
7746}
7747
7748#[no_mangle]
7756pub unsafe extern "C" fn xmlGetRefs(doc: *mut _xmlDoc, id: *const xmlChar) -> *mut c_void {
7757 crate::xml::validation::get_refs(doc, id) as *mut c_void
7758}
7759
7760#[no_mangle]
7768pub unsafe extern "C" fn xmlIsID(
7769 doc: *mut _xmlDoc,
7770 elem: *mut _xmlNode,
7771 attr: *mut _xmlAttr,
7772) -> c_int {
7773 crate::xml::validation::is_id(doc, elem, attr)
7774}
7775
7776#[no_mangle]
7784pub unsafe extern "C" fn xmlIsRef(
7785 doc: *mut _xmlDoc,
7786 elem: *mut _xmlNode,
7787 attr: *mut _xmlAttr,
7788) -> c_int {
7789 crate::xml::validation::is_ref(doc, elem, attr)
7790}
7791
7792#[no_mangle]
7800pub unsafe extern "C" fn xmlGetDtdElementDesc(
7801 dtd: *mut _xmlDtd,
7802 name: *const xmlChar,
7803) -> *mut _xmlElement {
7804 crate::xml::validation::get_dtd_element_desc(dtd, name)
7805}
7806
7807#[no_mangle]
7817pub unsafe extern "C" fn xmlGetDtdAttrDesc(
7818 dtd: *mut _xmlDtd,
7819 elem: *const xmlChar,
7820 name: *const xmlChar,
7821) -> *mut _xmlAttribute {
7822 crate::xml::validation::get_dtd_attr_desc(dtd, elem, name)
7823}
7824
7825#[no_mangle]
7835pub unsafe extern "C" fn xmlGetDtdQElementDesc(
7836 dtd: *mut _xmlDtd,
7837 name: *const xmlChar,
7838 prefix: *const xmlChar,
7839) -> *mut _xmlElement {
7840 crate::xml::validation::get_dtd_qelement_desc(dtd, name, prefix)
7841}
7842
7843#[no_mangle]
7854pub unsafe extern "C" fn xmlGetDtdQAttrDesc(
7855 dtd: *mut _xmlDtd,
7856 elem: *const xmlChar,
7857 name: *const xmlChar,
7858 prefix: *const xmlChar,
7859) -> *mut _xmlAttribute {
7860 crate::xml::validation::get_dtd_qattr_desc(dtd, elem, name, prefix)
7861}
7862
7863#[no_mangle]
7871pub unsafe extern "C" fn xmlGetDtdNotationDesc(
7872 dtd: *mut _xmlDtd,
7873 name: *const xmlChar,
7874) -> *mut _xmlNotation {
7875 crate::xml::validation::get_dtd_notation_desc(dtd, name)
7876}
7877
7878#[no_mangle]
7886pub unsafe extern "C" fn xmlValidateRoot(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
7887 crate::xml::validation::validate_root(ctxt, doc)
7888}
7889
7890#[no_mangle]
7900pub unsafe extern "C" fn xmlValidateContent(
7901 ctxt: *mut _xmlValidCtxt,
7902 node: *mut _xmlNode,
7903 doc: *mut _xmlDoc,
7904) -> c_int {
7905 crate::xml::validation::validate_content(ctxt, node, doc)
7906}
7907
7908#[no_mangle]
7916pub unsafe extern "C" fn xmlIsMixedElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
7917 crate::xml::validation::is_mixed_element(doc, name)
7918}
7919
7920#[no_mangle]
7928pub unsafe extern "C" fn xmlIsEmptyElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
7929 crate::xml::validation::is_empty_element(doc, name)
7930}
7931
7932#[no_mangle]
7942pub unsafe extern "C" fn xmlValidateDtd(
7943 ctxt: *mut _xmlValidCtxt,
7944 doc: *mut _xmlDoc,
7945 dtd: *mut _xmlDtd,
7946) -> c_int {
7947 crate::xml::validation::validate_dtd(ctxt, doc, dtd)
7948}
7949
7950#[no_mangle]
7958pub unsafe extern "C" fn xmlValidateDtdFinal(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
7959 crate::xml::validation::validate_dtd_final(ctxt, doc)
7960}
7961
7962#[no_mangle]
7972pub unsafe extern "C" fn xmlValidateEnumeration(
7973 ctxt: *mut _xmlValidCtxt,
7974 value: *const xmlChar,
7975 tree: *mut _xmlEnumeration,
7976) -> c_int {
7977 crate::xml::validation::validate_enumeration(ctxt, value, tree)
7978}
7979
7980#[no_mangle]
7993pub const extern "C" fn xmlGetBinaryPath() -> *mut c_char {
7994 ptr::null_mut()
7996}
7997
7998#[no_mangle]
8006pub const extern "C" fn xmlGetHomeOfBinary() -> *mut c_char {
8007 ptr::null_mut()
8009}
8010
8011#[no_mangle]
8022pub unsafe extern "C" fn xmlSAX2StartDocument(ctx: *mut c_void) {
8023 crate::xml::sax::default::default_sax_handler::startDocument(ctx)
8024}
8025
8026#[no_mangle]
8028pub unsafe extern "C" fn xmlSAX2EndDocument(ctx: *mut c_void) {
8029 crate::xml::sax::default::default_sax_handler::endDocument(ctx)
8030}
8031
8032#[no_mangle]
8034pub unsafe extern "C" fn xmlSAX2StartElementNs(
8035 ctx: *mut c_void,
8036 localname: *const xmlChar,
8037 prefix: *const xmlChar,
8038 URI: *const xmlChar,
8039 nb_namespaces: c_int,
8040 namespaces: *mut *const xmlChar,
8041 nb_attributes: c_int,
8042 nb_defaulted: c_int,
8043 attributes: *mut *const xmlChar,
8044) {
8045 crate::xml::sax::default::default_sax_handler::startElementNs(
8046 ctx,
8047 localname,
8048 prefix,
8049 URI,
8050 nb_namespaces,
8051 namespaces,
8052 nb_attributes,
8053 nb_defaulted,
8054 attributes,
8055 )
8056}
8057
8058#[no_mangle]
8060pub unsafe extern "C" fn xmlSAX2EndElementNs(
8061 ctx: *mut c_void,
8062 localname: *const xmlChar,
8063 prefix: *const xmlChar,
8064 URI: *const xmlChar,
8065) {
8066 crate::xml::sax::default::default_sax_handler::endElementNs(ctx, localname, prefix, URI)
8067}
8068
8069#[no_mangle]
8071pub unsafe extern "C" fn xmlSAX2Characters(ctx: *mut c_void, ch: *const xmlChar, len: c_int) {
8072 crate::xml::sax::default::default_sax_handler::characters(ctx, ch, len)
8073}
8074
8075#[no_mangle]
8077pub unsafe extern "C" fn xmlSAX2IgnorableWhitespace(
8078 ctx: *mut c_void,
8079 ch: *const xmlChar,
8080 len: c_int,
8081) {
8082 crate::xml::sax::default::default_sax_handler::ignorableWhitespace(ctx, ch, len)
8083}
8084
8085#[no_mangle]
8087pub unsafe extern "C" fn xmlSAX2Comment(ctx: *mut c_void, value: *const xmlChar) {
8088 crate::xml::sax::default::default_sax_handler::comment(ctx, value)
8089}
8090
8091#[no_mangle]
8093pub unsafe extern "C" fn xmlSAX2ProcessingInstruction(
8094 ctx: *mut c_void,
8095 target: *const xmlChar,
8096 data: *const xmlChar,
8097) {
8098 crate::xml::sax::default::default_sax_handler::processingInstruction(ctx, target, data)
8099}
8100
8101#[no_mangle]
8103pub unsafe extern "C" fn xmlSAX2CDataBlock(ctx: *mut c_void, value: *const xmlChar, len: c_int) {
8104 crate::xml::sax::default::default_sax_handler::cdataBlock(ctx, value, len)
8105}
8106
8107#[no_mangle]
8109pub unsafe extern "C" fn xmlSAX2InternalSubset(
8110 ctx: *mut c_void,
8111 name: *const xmlChar,
8112 ExternalID: *const xmlChar,
8113 SystemID: *const xmlChar,
8114) {
8115 crate::xml::sax::default::default_sax_handler::internalSubset(ctx, name, ExternalID, SystemID)
8116}
8117
8118#[no_mangle]
8120pub unsafe extern "C" fn xmlSAX2ExternalSubset(
8121 ctx: *mut c_void,
8122 name: *const xmlChar,
8123 ExternalID: *const xmlChar,
8124 SystemID: *const xmlChar,
8125) {
8126 crate::xml::sax::default::default_sax_handler::externalSubset(ctx, name, ExternalID, SystemID)
8127}
8128
8129#[no_mangle]
8131pub unsafe extern "C" fn xmlSAX2EntityDecl(
8132 ctx: *mut c_void,
8133 name: *const xmlChar,
8134 type_: c_int,
8135 publicId: *const xmlChar,
8136 systemId: *const xmlChar,
8137 content: *mut xmlChar,
8138) {
8139 crate::xml::sax::default::default_sax_handler::entityDecl(
8140 ctx, name, type_, publicId, systemId, content,
8141 )
8142}
8143
8144#[no_mangle]
8146pub const unsafe extern "C" fn xmlSAX2AttributeDecl(
8147 ctx: *mut c_void,
8148 elem: *const xmlChar,
8149 fullname: *const xmlChar,
8150 type_: c_int,
8151 def: c_int,
8152 defaultValue: *const xmlChar,
8153 tree: *mut crate::abi::structs::_xmlEnumeration,
8154) {
8155 crate::xml::sax::default::default_sax_handler::attributeDecl(
8156 ctx,
8157 elem,
8158 fullname,
8159 type_,
8160 def,
8161 defaultValue,
8162 tree,
8163 )
8164}
8165
8166#[no_mangle]
8168pub const unsafe extern "C" fn xmlSAX2ElementDecl(
8169 ctx: *mut c_void,
8170 name: *const xmlChar,
8171 type_: c_int,
8172 content: *mut crate::abi::structs::_xmlElementContent,
8173) {
8174 crate::xml::sax::default::default_sax_handler::elementDecl(ctx, name, type_, content)
8175}
8176
8177#[no_mangle]
8179pub const unsafe extern "C" fn xmlSAX2NotationDecl(
8180 ctx: *mut c_void,
8181 name: *const xmlChar,
8182 publicId: *const xmlChar,
8183 systemId: *const xmlChar,
8184) {
8185 crate::xml::sax::default::default_sax_handler::notationDecl(ctx, name, publicId, systemId)
8186}
8187
8188#[no_mangle]
8190pub const unsafe extern "C" fn xmlSAX2UnparsedEntityDecl(
8191 ctx: *mut c_void,
8192 name: *const xmlChar,
8193 publicId: *const xmlChar,
8194 systemId: *const xmlChar,
8195 notationName: *const xmlChar,
8196) {
8197 crate::xml::sax::default::default_sax_handler::unparsedEntityDecl(
8198 ctx,
8199 name,
8200 publicId,
8201 systemId,
8202 notationName,
8203 )
8204}
8205
8206#[no_mangle]
8208pub const unsafe extern "C" fn xmlSAX2ResolveEntity(
8209 ctx: *mut c_void,
8210 publicId: *const xmlChar,
8211 systemId: *const xmlChar,
8212) -> *mut crate::abi::structs::_xmlParserInput {
8213 crate::xml::sax::default::default_sax_handler::resolveEntity(ctx, publicId, systemId)
8214}
8215
8216#[no_mangle]
8218pub const unsafe extern "C" fn xmlSAX2IsStandalone(ctx: *mut c_void) -> c_int {
8219 crate::xml::sax::default::default_sax_handler::isStandalone(ctx)
8220}
8221
8222#[no_mangle]
8224pub unsafe extern "C" fn xmlSAX2HasInternalSubset(ctx: *mut c_void) -> c_int {
8225 crate::xml::sax::default::default_sax_handler::hasInternalSubset(ctx)
8226}
8227
8228#[no_mangle]
8230pub unsafe extern "C" fn xmlSAX2HasExternalSubset(ctx: *mut c_void) -> c_int {
8231 crate::xml::sax::default::default_sax_handler::hasExternalSubset(ctx)
8232}
8233
8234#[no_mangle]
8236pub unsafe extern "C" fn xmlSAX2GetEntity(
8237 ctx: *mut c_void,
8238 name: *const xmlChar,
8239) -> *mut crate::abi::structs::_xmlEntity {
8240 crate::xml::sax::default::default_sax_handler::getEntity(ctx, name)
8241}
8242
8243#[no_mangle]
8245pub unsafe extern "C" fn xmlSAX2GetParameterEntity(
8246 ctx: *mut c_void,
8247 name: *const xmlChar,
8248) -> *mut crate::abi::structs::_xmlEntity {
8249 crate::xml::sax::default::default_sax_handler::getParameterEntity(ctx, name)
8250}
8251
8252#[no_mangle]
8255pub unsafe extern "C" fn xmlSAX2GetLineNumber(ctx: *mut c_void) -> c_int {
8256 crate::xml::sax::default::default_sax_handler::getLineNumber(ctx)
8257}
8258
8259#[no_mangle]
8261pub unsafe extern "C" fn xmlSAX2GetColumnNumber(ctx: *mut c_void) -> c_int {
8262 crate::xml::sax::default::default_sax_handler::getColumnNumber(ctx)
8263}
8264
8265#[no_mangle]
8267pub const unsafe extern "C" fn xmlSAX2GetPublicId(ctx: *mut c_void) -> *const xmlChar {
8268 crate::xml::sax::default::default_sax_handler::getPublicId(ctx)
8269}
8270
8271#[no_mangle]
8273pub unsafe extern "C" fn xmlSAX2GetSystemId(ctx: *mut c_void) -> *const xmlChar {
8274 crate::xml::sax::default::default_sax_handler::getSystemId(ctx)
8275}
8276
8277#[no_mangle]
8281pub unsafe extern "C" fn xmlSAX2StartElement(
8282 ctx: *mut c_void,
8283 name: *const xmlChar,
8284 atts: *mut *const xmlChar,
8285) {
8286 crate::xml::sax::dispatch::SaxDispatcher::sax1_start_element(ctx, name, atts);
8290}
8291
8292#[no_mangle]
8294pub unsafe extern "C" fn xmlSAX2EndElement(ctx: *mut c_void, name: *const xmlChar) {
8295 crate::xml::sax::dispatch::SaxDispatcher::sax1_end_element(ctx, name);
8296}
8297
8298#[no_mangle]
8300pub const unsafe extern "C" fn xmlSAX2SetDocumentLocator(
8301 ctx: *mut c_void,
8302 loc: *mut crate::abi::callbacks::_xmlSAXLocator,
8303) {
8304 crate::xml::sax::default::default_sax_handler::setDocumentLocator(ctx, loc)
8305}
8306
8307#[no_mangle]
8309pub unsafe extern "C" fn xmlSAX2Reference(ctx: *mut c_void, name: *const xmlChar) {
8310 crate::xml::sax::default::default_sax_handler::reference(ctx, name)
8311}
8312
8313#[cfg(test)]
8314mod tests {
8315 use super::xml_number_to_string;
8316
8317 #[allow(clippy::approx_constant)]
8323 #[test]
8324 fn test_xml_number_to_string_parity_cases() {
8325 let cases: &[(f64, &str)] = &[
8326 (1234567.891, "1234567.891"),
8327 (0.1 + 0.2, "0.3"),
8328 (1.0 / 3.0, "0.333333333333333"),
8329 (1e20, "1e+20"),
8330 (1e-5, "0.00001"),
8331 (123456789012345678901234567890.0, "1.23456789012346e+29"),
8332 (1e100, "1e+100"),
8333 (-1e100, "-1e+100"),
8334 (1.5e-100, "1.5e-100"),
8335 (1e9, "1000000000"),
8336 (0.00001, "0.00001"),
8337 (9.99e-6, "9.99e-06"),
8338 (2147483646.0, "2147483646"),
8339 (2147483648.0, "2.147483648e+09"),
8340 (-2147483647.0, "-2147483647"),
8341 (-2147483649.0, "-2.147483649e+09"),
8342 (0.5, "0.5"),
8343 (1.0 / 7.0, "0.142857142857143"),
8344 (2.675, "2.675"),
8345 (3.141592653589793, "3.141592653589793"),
8346 (-0.0, "0"),
8347 (0.0, "0"),
8348 (f64::INFINITY, "Infinity"),
8349 (f64::NEG_INFINITY, "-Infinity"),
8350 (f64::NAN, "NaN"),
8351 (0.30000000000000004, "0.3"),
8352 (2.2250738585072014e-308, "2.2250738585072e-308"),
8353 (5e-324, "4.94065645841247e-324"),
8354 ];
8355 for (n, expected) in cases {
8356 assert_eq!(&xml_number_to_string(*n), expected, "value: {}", n);
8357 }
8358 }
8359
8360 #[test]
8370 fn test_xml_new_child_with_content() {
8371 unsafe {
8372 let doc =
8373 crate::xml::tree::new_doc(c"1.0".as_ptr() as *const crate::abi::types::xmlChar);
8374 assert!(!doc.is_null());
8375 let root = crate::xml::tree::new_node(
8376 core::ptr::null_mut(),
8377 c"root".as_ptr() as *const crate::abi::types::xmlChar,
8378 );
8379 assert!(!root.is_null());
8380 crate::xml::tree::doc_set_root_element(doc, root);
8381
8382 let child = super::xmlNewChild(
8383 root,
8384 core::ptr::null_mut(),
8385 c"node1".as_ptr() as *const crate::abi::types::xmlChar,
8386 c"content of node 1".as_ptr() as *const crate::abi::types::xmlChar,
8387 );
8388 assert!(!child.is_null());
8389 assert!(
8390 !(*child).children.is_null(),
8391 "content must become a text child"
8392 );
8393 assert_eq!(
8394 crate::abi::types::xmlElementType::XML_TEXT_NODE as i32,
8395 (*(*child).children).type_
8396 );
8397 let text = crate::xml::string::xmlstr_to_bytes((*(*child).children).content);
8398 assert_eq!(text, b"content of node 1");
8399
8400 let empty = super::xmlNewChild(
8402 root,
8403 core::ptr::null_mut(),
8404 c"node2".as_ptr() as *const crate::abi::types::xmlChar,
8405 core::ptr::null(),
8406 );
8407 assert!(!empty.is_null());
8408 assert!((*empty).children.is_null());
8409
8410 crate::xml::tree::free_doc(doc);
8411 }
8412 }
8413}