1#![allow(non_snake_case)]
37#![allow(unused_variables)]
38#![allow(clippy::missing_safety_doc)]
39#![allow(clippy::not_unsafe_ptr_arg_deref)]
40
41use core::ffi::c_void;
42use core::ptr;
43use once_cell::sync::Lazy;
44use parking_lot::Mutex;
45use std::collections::HashMap;
46use std::ffi::CStr;
47use std::mem::size_of;
48use std::os::raw::{c_char, c_int, c_uint};
49
50use crate::xml::xinclude;
51use crate::xml::xpath::ast::CompiledExpr;
52use crate::xml::xpath::context::XPathContext;
53use crate::xml::xpath::types::{NodeSet, XPathValue};
54use crate::xml::xpointer;
55
56use crate::abi::allocator::*;
57use crate::abi::callbacks::*;
58use crate::abi::structs::*;
59use crate::abi::types::*;
60
61#[no_mangle]
76pub unsafe extern "C" fn xmlInitParser() {
77 crate::internal::globals::init_parser();
78}
79
80#[no_mangle]
90pub unsafe extern "C" fn xmlCleanupParser() {
91 crate::internal::globals::cleanup_parser();
92}
93
94#[no_mangle]
104pub unsafe extern "C" fn xmlInitThreads() -> c_int {
105 crate::internal::globals::init_threads()
106}
107
108#[no_mangle]
116pub unsafe extern "C" fn xmlCleanupThreads() {
117 crate::xml::threads::cleanup_threads();
118}
119
120#[no_mangle]
128pub extern "C" fn xmlIsInitialized() -> c_int {
129 if crate::abi::versioning::is_initialized() {
130 1
131 } else {
132 0
133 }
134}
135
136#[no_mangle]
145pub unsafe extern "C" fn xmlLockLibrary() {
146 crate::xml::threads::lock_library();
147}
148
149#[no_mangle]
157pub unsafe extern "C" fn xmlUnlockLibrary() {
158 crate::xml::threads::unlock_library();
159}
160
161#[no_mangle]
178pub unsafe extern "C" fn xmlSetGenericErrorFunc(
179 ctx: *mut c_void,
180 handler: Option<xmlGenericErrorFunc>,
181) {
182 unsafe { crate::xml::errors::set_generic_error_func(ctx, handler) };
184}
185
186#[no_mangle]
198pub unsafe extern "C" fn xmlSetStructuredErrorFunc(
199 ctx: *mut c_void,
200 handler: Option<xmlStructuredErrorFunc>,
201) {
202 unsafe { crate::xml::errors::set_structured_error_func(ctx, handler) };
204}
205
206#[no_mangle]
217pub extern "C" fn xmlGetLastError() -> *mut _xmlError {
218 crate::xml::errors::get_last_error()
219}
220
221#[no_mangle]
235pub unsafe extern "C" fn xmlCopyError(from: *const _xmlError, to: *mut _xmlError) -> c_int {
236 unsafe { crate::xml::errors::copy_error(from, to) }
238}
239
240#[no_mangle]
252pub unsafe extern "C" fn xmlResetError(err: *mut _xmlError) {
253 unsafe { crate::xml::errors::reset_error(err) };
255}
256
257#[no_mangle]
270pub unsafe extern "C" fn xmlRaiseError(
271 ctxt: *mut c_void,
272 ctxt2: *mut c_void,
273 ctxt3: *mut c_void,
274 ctxt4: *mut c_void,
275 ctxt5: *mut c_void,
276 domain: c_int,
277 code: c_int,
278 level: c_int,
279 file: *const c_char,
280 line: c_int,
281 str1: *const c_char,
282 str2: *const c_char,
283 str3: *const c_char,
284 int1: c_int,
285 int2: c_int,
286 msg: *const c_char,
287) {
288 unsafe {
290 crate::xml::errors::raise_error(
291 ctxt, ctxt2, ctxt3, ctxt4, ctxt5, domain, code, level, file, line, str1, str2, str3,
292 int1, int2, msg,
293 );
294 }
295}
296
297#[no_mangle]
305pub extern "C" fn xmlResetLastError() {
306 crate::xml::errors::reset_last_error();
307}
308
309#[no_mangle]
325pub unsafe extern "C" fn xmlStrdup(cur: *const xmlChar) -> *mut xmlChar {
326 if cur.is_null() {
327 return ptr::null_mut();
328 }
329 let len = unsafe { xmlStrlen(cur) };
330 let size = len + 1;
331 let new_ptr = unsafe { xmlMalloc(size as usize) };
332 if new_ptr.is_null() {
333 return ptr::null_mut();
334 }
335 unsafe {
336 ptr::copy_nonoverlapping(cur as *const u8, new_ptr as *mut u8, size as usize);
337 }
338 new_ptr as *mut xmlChar
339}
340
341#[no_mangle]
353pub unsafe extern "C" fn xmlStrndup(cur: *const xmlChar, len: c_int) -> *mut xmlChar {
354 if cur.is_null() || len <= 0 {
355 return ptr::null_mut();
356 }
357 let size = len as usize + 1;
358 let new_ptr = unsafe { xmlMalloc(size) };
359 if new_ptr.is_null() {
360 return ptr::null_mut();
361 }
362 unsafe {
363 ptr::copy_nonoverlapping(cur as *const u8, new_ptr as *mut u8, len as usize);
364 *(new_ptr.add(len as usize) as *mut u8) = 0;
365 }
366 new_ptr as *mut xmlChar
367}
368
369#[no_mangle]
381pub unsafe extern "C" fn xmlStrlen(str: *const xmlChar) -> c_int {
382 if str.is_null() {
383 return 0;
384 }
385 unsafe { libc::strlen(str as *const c_char) as c_int }
386}
387
388#[no_mangle]
399pub unsafe extern "C" fn xmlStrcmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
400 if str1.is_null() && str2.is_null() {
401 return 0;
402 }
403 if str1.is_null() {
404 return -1;
405 }
406 if str2.is_null() {
407 return 1;
408 }
409 unsafe { libc::strcmp(str1 as *const c_char, str2 as *const c_char) as c_int }
410}
411
412#[no_mangle]
420pub unsafe extern "C" fn xmlStrncmp(
421 str1: *const xmlChar,
422 str2: *const xmlChar,
423 len: c_int,
424) -> c_int {
425 if len <= 0 {
426 return 0;
427 }
428 if str1.is_null() && str2.is_null() {
429 return 0;
430 }
431 if str1.is_null() {
432 return -1;
433 }
434 if str2.is_null() {
435 return 1;
436 }
437 unsafe { libc::strncmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int }
438}
439
440#[no_mangle]
448pub unsafe extern "C" fn xmlStrcasecmp(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
449 if str1.is_null() && str2.is_null() {
450 return 0;
451 }
452 if str1.is_null() {
453 return -1;
454 }
455 if str2.is_null() {
456 return 1;
457 }
458 unsafe { libc::strcasecmp(str1 as *const c_char, str2 as *const c_char) as c_int }
459}
460
461#[no_mangle]
469pub unsafe extern "C" fn xmlStrncasecmp(
470 str1: *const xmlChar,
471 str2: *const xmlChar,
472 len: c_int,
473) -> c_int {
474 if len <= 0 {
475 return 0;
476 }
477 if str1.is_null() && str2.is_null() {
478 return 0;
479 }
480 if str1.is_null() {
481 return -1;
482 }
483 if str2.is_null() {
484 return 1;
485 }
486 unsafe {
487 libc::strncasecmp(str1 as *const c_char, str2 as *const c_char, len as usize) as c_int
488 }
489}
490
491#[no_mangle]
501pub unsafe extern "C" fn xmlStrEqual(str1: *const xmlChar, str2: *const xmlChar) -> c_int {
502 if str1.is_null() && str2.is_null() {
503 return 1;
504 }
505 if str1.is_null() || str2.is_null() {
506 return 0;
507 }
508 unsafe { (libc::strcmp(str1 as *const c_char, str2 as *const c_char) == 0) as c_int }
509}
510
511#[no_mangle]
522pub unsafe extern "C" fn xmlStrQEqual(
523 pref: *const xmlChar,
524 name: *const xmlChar,
525 str: *const xmlChar,
526) -> c_int {
527 if name.is_null() || str.is_null() {
528 return 0;
529 }
530 if pref.is_null() {
531 return unsafe { xmlStrEqual(name, str) };
532 }
533 let pref_len = unsafe { xmlStrlen(pref) };
535 let name_len = unsafe { xmlStrlen(name) };
536 let total_len = pref_len + 1 + name_len;
537 let str_len = unsafe { xmlStrlen(str) };
538 if total_len != str_len {
539 return 0;
540 }
541 if unsafe {
543 libc::strncmp(
544 pref as *const c_char,
545 str as *const c_char,
546 pref_len as usize,
547 )
548 } != 0
549 {
550 return 0;
551 }
552 if unsafe { *str.add(pref_len as usize) } != b':' as xmlChar {
554 return 0;
555 }
556 (unsafe {
558 libc::strncmp(
559 name as *const c_char,
560 str.add((pref_len + 1) as usize) as *const c_char,
561 name_len as usize,
562 ) == 0
563 }) as c_int
564}
565
566#[no_mangle]
580pub unsafe extern "C" fn xmlStrcat(cur: *mut xmlChar, add: *const xmlChar) -> *mut xmlChar {
581 if add.is_null() {
582 return cur;
583 }
584 if cur.is_null() {
585 return unsafe { xmlStrdup(add) };
586 }
587 let cur_len = unsafe { xmlStrlen(cur) } as usize;
588 let add_len = unsafe { xmlStrlen(add) } as usize;
589 let new_size = cur_len + add_len + 1;
590 let new_ptr = unsafe { xmlRealloc(cur as *mut c_void, new_size) };
591 if new_ptr.is_null() {
592 return ptr::null_mut();
593 }
594 unsafe {
595 ptr::copy_nonoverlapping(add as *const u8, (new_ptr as *mut u8).add(cur_len), add_len);
596 *((new_ptr as *mut u8).add(cur_len + add_len)) = 0;
597 }
598 new_ptr as *mut xmlChar
599}
600
601#[no_mangle]
613pub unsafe extern "C" fn xmlStrncat(
614 cur: *mut xmlChar,
615 add: *const xmlChar,
616 len: c_int,
617) -> *mut xmlChar {
618 if add.is_null() || len <= 0 {
619 return cur;
620 }
621 let len = len as usize;
622 if cur.is_null() {
623 return unsafe { xmlStrndup(add, len as c_int) };
624 }
625 let cur_len = unsafe { xmlStrlen(cur) } as usize;
626 let new_size = cur_len + len + 1;
627 let new_ptr = unsafe { xmlRealloc(cur as *mut c_void, new_size) };
628 if new_ptr.is_null() {
629 return ptr::null_mut();
630 }
631 unsafe {
632 ptr::copy_nonoverlapping(add as *const u8, (new_ptr as *mut u8).add(cur_len), len);
633 *((new_ptr as *mut u8).add(cur_len + len)) = 0;
634 }
635 new_ptr as *mut xmlChar
636}
637
638#[no_mangle]
646pub unsafe extern "C" fn xmlStrncatNew(
647 str1: *const xmlChar,
648 str2: *const xmlChar,
649 len: c_int,
650) -> *mut xmlChar {
651 let mut result: *mut xmlChar = ptr::null_mut();
652 if !str1.is_null() {
653 result = unsafe { xmlStrdup(str1) };
654 }
655 if !str2.is_null() && len > 0 {
656 result = unsafe { xmlStrncat(result, str2, len) };
657 }
658 result
659}
660
661#[no_mangle]
674pub unsafe extern "C" fn xmlStrcpy(dst: *mut xmlChar, src: *const xmlChar) -> *mut xmlChar {
675 if dst.is_null() || src.is_null() {
676 return dst;
677 }
678 let len = unsafe { xmlStrlen(src) } as usize + 1;
679 unsafe {
680 ptr::copy_nonoverlapping(src as *const u8, dst as *mut u8, len);
681 }
682 dst
683}
684
685#[no_mangle]
693pub unsafe extern "C" fn xmlStrncpy(
694 dst: *mut xmlChar,
695 src: *const xmlChar,
696 len: c_int,
697) -> *mut xmlChar {
698 if dst.is_null() || src.is_null() || len <= 0 {
699 return dst;
700 }
701 let len = len as usize;
702 let src_len = unsafe { xmlStrlen(src) } as usize;
703 let copy_len = if src_len < len { src_len } else { len - 1 };
704 unsafe {
705 ptr::copy_nonoverlapping(src as *const u8, dst as *mut u8, copy_len);
706 *dst.add(copy_len) = 0;
707 }
708 dst
709}
710
711#[no_mangle]
721pub unsafe extern "C" fn xmlStrsub(str: *const xmlChar, start: c_int, len: c_int) -> *mut xmlChar {
722 if str.is_null() || start < 0 || len < 0 {
723 return ptr::null_mut();
724 }
725 let str_len = unsafe { xmlStrlen(str) };
726 if start >= str_len {
727 return unsafe { xmlStrdup(b"\0" as *const u8 as *const xmlChar) };
728 }
729 let actual_len = if start + len > str_len {
730 str_len - start
731 } else {
732 len
733 };
734 unsafe { xmlStrndup(str.add(start as usize), actual_len) }
735}
736
737#[no_mangle]
754pub unsafe extern "C" fn xmlNewDoc(version: *const xmlChar) -> *mut _xmlDoc {
755 crate::xml::tree::new_doc(version)
756}
757
758#[no_mangle]
770pub unsafe extern "C" fn xmlFreeDoc(doc: *mut _xmlDoc) {
771 crate::xml::tree::free_doc(doc);
772}
773
774#[no_mangle]
788pub unsafe extern "C" fn xmlNewNode(ns: *mut _xmlNs, name: *const xmlChar) -> *mut _xmlNode {
789 crate::xml::tree::new_node(ns, name)
790}
791
792#[no_mangle]
805pub unsafe extern "C" fn xmlFreeNode(node: *mut _xmlNode) {
806 crate::xml::tree::free_node(node);
807}
808
809#[no_mangle]
821pub unsafe extern "C" fn xmlUnlinkNode(node: *mut _xmlNode) {
822 crate::xml::tree::unlink_node(node);
823}
824
825#[no_mangle]
839pub unsafe extern "C" fn xmlAddChild(parent: *mut _xmlNode, cur: *mut _xmlNode) -> *mut _xmlNode {
840 crate::xml::tree::add_child(parent, cur)
841}
842
843#[no_mangle]
855pub unsafe extern "C" fn xmlAddSibling(
856 cur: *mut _xmlNode,
857 sibling: *mut _xmlNode,
858) -> *mut _xmlNode {
859 crate::xml::tree::add_sibling(cur, sibling)
860}
861
862#[no_mangle]
881pub unsafe extern "C" fn xmlNewChild(
882 parent: *mut _xmlNode,
883 ns: *mut _xmlNs,
884 name: *const xmlChar,
885 content: *const xmlChar,
886) -> *mut _xmlNode {
887 crate::xml::tree::new_child(parent, ns, name)
888}
889
890#[no_mangle]
905pub unsafe extern "C" fn xmlDocSetRootElement(
906 doc: *mut _xmlDoc,
907 root: *mut _xmlNode,
908) -> *mut _xmlNode {
909 crate::xml::tree::doc_set_root_element(doc, root)
910}
911
912#[no_mangle]
922pub extern "C" fn xmlDocGetRootElement(doc: *const _xmlDoc) -> *mut _xmlNode {
923 crate::xml::tree::doc_get_root_element(doc as *mut _xmlDoc)
924}
925
926#[no_mangle]
939pub unsafe extern "C" fn xmlCopyNode(node: *const _xmlNode, extended: c_int) -> *mut _xmlNode {
940 crate::xml::tree::copy_node(node, extended)
941}
942
943#[no_mangle]
953pub unsafe extern "C" fn xmlCopyDoc(doc: *const _xmlDoc, recursive: c_int) -> *mut _xmlDoc {
954 crate::xml::tree::copy_doc(doc, recursive)
955}
956
957#[no_mangle]
968pub unsafe extern "C" fn xmlNewText(content: *const xmlChar) -> *mut _xmlNode {
969 crate::xml::tree::new_text(content)
970}
971
972#[no_mangle]
980pub unsafe extern "C" fn xmlNewComment(content: *const xmlChar) -> *mut _xmlNode {
981 crate::xml::tree::new_comment(content)
982}
983
984#[no_mangle]
992pub unsafe extern "C" fn xmlNewPI(name: *const xmlChar, content: *const xmlChar) -> *mut _xmlNode {
993 crate::xml::tree::new_pi(name, content)
994}
995
996#[no_mangle]
1004pub unsafe extern "C" fn xmlNewCDataBlock(
1005 doc: *mut _xmlDoc,
1006 content: *const xmlChar,
1007 len: c_int,
1008) -> *mut _xmlNode {
1009 crate::xml::tree::new_cdata_block(doc, content, len)
1010}
1011
1012#[no_mangle]
1026pub unsafe extern "C" fn xmlNewNs(
1027 node: *mut _xmlNode,
1028 href: *const xmlChar,
1029 prefix: *const xmlChar,
1030) -> *mut _xmlNs {
1031 crate::xml::tree::new_ns(node, href, prefix)
1032}
1033
1034#[no_mangle]
1042pub unsafe extern "C" fn xmlSetNs(node: *mut _xmlNode, ns: *mut _xmlNs) {
1043 crate::xml::tree::set_ns(node, ns);
1044}
1045
1046#[no_mangle]
1054pub unsafe extern "C" fn xmlGetNsList(
1055 doc: *mut _xmlDoc,
1056 node: *const _xmlNode,
1057) -> *mut *mut _xmlNs {
1058 crate::xml::tree::get_ns_list(doc, node as *mut _xmlNode)
1059}
1060
1061#[no_mangle]
1069pub unsafe extern "C" fn xmlSearchNs(
1070 doc: *mut _xmlDoc,
1071 node: *mut _xmlNode,
1072 nameSpace: *const xmlChar,
1073) -> *mut _xmlNs {
1074 crate::xml::tree::search_ns(doc, node, nameSpace)
1075}
1076
1077#[no_mangle]
1085pub unsafe extern "C" fn xmlSearchNsByHref(
1086 doc: *mut _xmlDoc,
1087 node: *mut _xmlNode,
1088 href: *const xmlChar,
1089) -> *mut _xmlNs {
1090 crate::xml::tree::search_ns_by_href(doc, node, href)
1091}
1092
1093#[no_mangle]
1110pub unsafe extern "C" fn xmlSetProp(
1111 node: *mut _xmlNode,
1112 name: *const xmlChar,
1113 value: *const xmlChar,
1114) -> *mut _xmlAttr {
1115 crate::xml::tree::set_prop(node, name, value)
1116}
1117
1118#[no_mangle]
1128pub unsafe extern "C" fn xmlGetProp(node: *const _xmlNode, name: *const xmlChar) -> *mut xmlChar {
1129 crate::xml::tree::get_prop(node as *mut _xmlNode, name)
1130}
1131
1132#[no_mangle]
1140pub unsafe extern "C" fn xmlGetNsProp(
1141 node: *const _xmlNode,
1142 name: *const xmlChar,
1143 nameSpace: *const xmlChar,
1144) -> *mut xmlChar {
1145 crate::xml::tree::get_ns_prop(node as *mut _xmlNode, name, nameSpace)
1146}
1147
1148#[no_mangle]
1157pub unsafe extern "C" fn xmlSetNsProp(
1158 node: *mut _xmlNode,
1159 ns: *mut _xmlNs,
1160 name: *const xmlChar,
1161 value: *const xmlChar,
1162) -> *mut _xmlAttr {
1163 crate::xml::tree::set_ns_prop(node, ns, name, value)
1164}
1165
1166#[no_mangle]
1176pub unsafe extern "C" fn xmlRemoveProp(attr: *mut _xmlAttr) -> c_int {
1177 crate::xml::tree::remove_prop(attr)
1178}
1179
1180#[no_mangle]
1188pub extern "C" fn xmlGetIntSubset(doc: *const _xmlDoc) -> *mut _xmlDtd {
1189 crate::xml::tree::get_int_subset(doc)
1190}
1191
1192#[no_mangle]
1201pub unsafe extern "C" fn xmlNewDtd(
1202 doc: *mut _xmlDoc,
1203 name: *const xmlChar,
1204 ExternalID: *const xmlChar,
1205 SystemID: *const xmlChar,
1206) -> *mut _xmlDtd {
1207 crate::xml::tree::new_dtd(doc, name, ExternalID, SystemID)
1208}
1209
1210#[no_mangle]
1220pub unsafe extern "C" fn xmlNewEntity(
1221 doc: *mut _xmlDoc,
1222 name: *const xmlChar,
1223 type_: c_int,
1224 ExternalID: *const xmlChar,
1225 SystemID: *const xmlChar,
1226 content: *const xmlChar,
1227) -> *mut _xmlEntity {
1228 crate::xml::tree::new_entity(doc, name, type_, ExternalID, SystemID, content)
1229}
1230
1231#[no_mangle]
1239pub unsafe extern "C" fn xmlGetDocEntity(
1240 doc: *const _xmlDoc,
1241 name: *const xmlChar,
1242) -> *mut _xmlEntity {
1243 crate::xml::tree::get_doc_entity(doc, name)
1244}
1245
1246#[no_mangle]
1254pub unsafe extern "C" fn xmlGetParameterEntity(
1255 doc: *const _xmlDoc,
1256 name: *const xmlChar,
1257) -> *mut _xmlEntity {
1258 crate::xml::tree::get_parameter_entity(doc, name)
1259}
1260
1261#[no_mangle]
1272pub unsafe extern "C" fn xmlCreateIntSubset(
1273 doc: *mut _xmlDoc,
1274 name: *const xmlChar,
1275 ExternalID: *const xmlChar,
1276 SystemID: *const xmlChar,
1277) -> *mut _xmlDtd {
1278 crate::xml::dtd::create_int_subset(doc, name, ExternalID, SystemID)
1279}
1280
1281#[no_mangle]
1289pub unsafe extern "C" fn xmlFreeDtd(dtd: *mut _xmlDtd) {
1290 crate::xml::dtd::free_dtd(dtd);
1291}
1292
1293#[no_mangle]
1303pub unsafe extern "C" fn xmlAddNotationDecl(
1304 dtd: *mut _xmlDtd,
1305 name: *const xmlChar,
1306 PublicID: *const xmlChar,
1307 SystemID: *const xmlChar,
1308) -> *mut _xmlNotation {
1309 crate::xml::dtd::add_notation_decl(dtd, name, PublicID, SystemID)
1310}
1311
1312#[no_mangle]
1320pub unsafe extern "C" fn xmlGetNotationDecl(
1321 dtd: *mut _xmlDtd,
1322 name: *const xmlChar,
1323) -> *mut _xmlNotation {
1324 crate::xml::dtd::get_notation_decl(dtd, name)
1325}
1326
1327#[no_mangle]
1335pub unsafe extern "C" fn xmlCopyNotation(notation: *mut _xmlNotation) -> *mut _xmlNotation {
1336 crate::xml::dtd::copy_notation(notation)
1337}
1338
1339#[no_mangle]
1347pub unsafe extern "C" fn xmlFreeNotation(notation: *mut _xmlNotation) {
1348 crate::xml::dtd::free_notation(notation);
1349}
1350
1351#[no_mangle]
1360pub unsafe extern "C" fn xmlAddElementDecl(
1361 dtd: *mut _xmlDtd,
1362 name: *const xmlChar,
1363 type_: c_int,
1364 content: *mut _xmlElementContent,
1365) -> *mut _xmlElement {
1366 crate::xml::dtd::add_element_decl(dtd, name, type_, content)
1367}
1368
1369#[no_mangle]
1377pub unsafe extern "C" fn xmlGetElementDecl(
1378 dtd: *mut _xmlDtd,
1379 name: *const xmlChar,
1380) -> *mut _xmlElement {
1381 crate::xml::dtd::get_element_decl(dtd, name)
1382}
1383
1384#[no_mangle]
1392pub unsafe extern "C" fn xmlCopyElement(elem: *mut _xmlElement) -> *mut _xmlElement {
1393 crate::xml::dtd::copy_element(elem)
1394}
1395
1396#[no_mangle]
1404pub unsafe extern "C" fn xmlFreeElement(elem: *mut _xmlElement) {
1405 crate::xml::dtd::free_element(elem);
1406}
1407
1408#[no_mangle]
1419pub unsafe extern "C" fn xmlAddAttributeDecl(
1420 dtd: *mut _xmlDtd,
1421 elem: *mut _xmlElement,
1422 name: *const xmlChar,
1423 type_: c_int,
1424 def: c_int,
1425 defaultValue: *const xmlChar,
1426 tree: *mut _xmlEnumeration,
1427) -> *mut _xmlAttribute {
1428 crate::xml::dtd::add_attribute_decl(dtd, elem, name, type_, def, defaultValue, tree)
1429}
1430
1431#[no_mangle]
1440pub unsafe extern "C" fn xmlGetAttributeDecl(
1441 dtd: *mut _xmlDtd,
1442 elem: *mut _xmlElement,
1443 name: *const xmlChar,
1444 namePrefix: c_int,
1445) -> *mut _xmlAttribute {
1446 crate::xml::dtd::get_attribute_decl(dtd, elem, name, namePrefix)
1447}
1448
1449#[no_mangle]
1457pub unsafe extern "C" fn xmlCopyAttribute(attr: *mut _xmlAttribute) -> *mut _xmlAttribute {
1458 crate::xml::dtd::copy_attribute_decl(attr)
1459}
1460
1461#[no_mangle]
1469pub unsafe extern "C" fn xmlFreeAttribute(attr: *mut _xmlAttribute) {
1470 crate::xml::dtd::free_attribute(attr);
1471}
1472
1473#[no_mangle]
1481pub unsafe extern "C" fn xmlNewElementContent(
1482 name: *const xmlChar,
1483 type_: c_int,
1484) -> *mut _xmlElementContent {
1485 crate::xml::dtd::create_content_model(name, type_)
1486}
1487
1488#[no_mangle]
1496pub unsafe extern "C" fn xmlCopyElementContent(
1497 content: *mut _xmlElementContent,
1498) -> *mut _xmlElementContent {
1499 crate::xml::dtd::copy_content_model(content)
1500}
1501
1502#[no_mangle]
1510pub unsafe extern "C" fn xmlFreeElementContent(cur: *mut _xmlElementContent) {
1511 crate::xml::dtd::free_content_model(cur);
1512}
1513
1514#[no_mangle]
1526pub unsafe extern "C" fn xmlAddEntity(
1527 dtd: *mut _xmlDtd,
1528 name: *const xmlChar,
1529 type_: c_int,
1530 ExternalID: *const xmlChar,
1531 SystemID: *const xmlChar,
1532 content: *const xmlChar,
1533) -> *mut _xmlEntity {
1534 crate::xml::entities::add_entity(dtd, name, type_, ExternalID, SystemID, content)
1535}
1536
1537#[no_mangle]
1545pub unsafe extern "C" fn xmlGetEntity(doc: *mut _xmlDoc, name: *const xmlChar) -> *mut _xmlEntity {
1546 crate::xml::entities::get_entity(doc, name)
1547}
1548
1549#[no_mangle]
1557pub unsafe extern "C" fn xmlCopyEntity(entity: *mut _xmlEntity) -> *mut _xmlEntity {
1558 crate::xml::entities::copy_entity(entity)
1559}
1560
1561#[no_mangle]
1569pub unsafe extern "C" fn xmlFreeEntity(entity: *mut _xmlEntity) {
1570 crate::xml::entities::free_entity(entity);
1571}
1572
1573#[no_mangle]
1581pub unsafe extern "C" fn xmlEncodeEntitiesReentrant(
1582 doc: *mut _xmlDoc,
1583 input: *const xmlChar,
1584) -> *mut xmlChar {
1585 crate::xml::entities::encode_entities_reentrant(doc, input)
1586}
1587
1588#[no_mangle]
1596pub extern "C" fn xmlGetLineNo(node: *const _xmlNode) -> c_int {
1597 crate::xml::tree::get_line_no(node)
1598}
1599
1600#[no_mangle]
1612pub unsafe extern "C" fn xmlNodeDump(
1613 buf: *mut _xmlBuffer,
1614 doc: *mut _xmlDoc,
1615 cur: *mut _xmlNode,
1616 level: c_int,
1617 format: c_int,
1618) -> c_int {
1619 if buf.is_null() || cur.is_null() {
1620 return -1;
1621 }
1622 crate::xml::tree::xmlNodeDump(buf, doc, cur, level, format)
1623}
1624
1625#[no_mangle]
1633pub unsafe extern "C" fn xmlDocDump(fp: *mut c_void, doc: *mut _xmlDoc) -> c_int {
1634 if fp.is_null() || doc.is_null() {
1635 return -1;
1636 }
1637 crate::xml::tree::xmlDocDump(fp, doc)
1638}
1639
1640#[no_mangle]
1648pub unsafe extern "C" fn xmlDocDumpFormatMemory(
1649 doc: *mut _xmlDoc,
1650 mem: *mut *mut xmlChar,
1651 size: *mut c_int,
1652 format: c_int,
1653) {
1654 if doc.is_null() || mem.is_null() || size.is_null() {
1655 return;
1656 }
1657 crate::xml::tree::xmlDocDumpFormatMemory(doc, mem, size, format)
1658}
1659
1660#[no_mangle]
1668pub unsafe extern "C" fn xmlDocDumpMemory(
1669 doc: *mut _xmlDoc,
1670 mem: *mut *mut xmlChar,
1671 size: *mut c_int,
1672) {
1673 if doc.is_null() || mem.is_null() || size.is_null() {
1674 return;
1675 }
1676 crate::xml::tree::xmlDocDumpMemory(doc, mem, size)
1677}
1678
1679#[no_mangle]
1687pub unsafe extern "C" fn xmlSaveFile(filename: *const c_char, cur: *mut _xmlDoc) -> c_int {
1688 if filename.is_null() || cur.is_null() {
1689 return -1;
1690 }
1691 crate::xml::tree::xmlSaveFile(filename, cur)
1692}
1693
1694#[no_mangle]
1702pub unsafe extern "C" fn xmlSaveFileEnc(
1703 filename: *const c_char,
1704 cur: *mut _xmlDoc,
1705 encoding: *const c_char,
1706) -> c_int {
1707 if filename.is_null() || cur.is_null() {
1708 return -1;
1709 }
1710 crate::xml::tree::xmlSaveFileEnc(filename, cur, encoding)
1711}
1712
1713#[no_mangle]
1721pub unsafe extern "C" fn xmlSaveFormatFile(
1722 filename: *const c_char,
1723 cur: *mut _xmlDoc,
1724 format: c_int,
1725) -> c_int {
1726 if filename.is_null() || cur.is_null() {
1727 return -1;
1728 }
1729 crate::xml::tree::xmlSaveFormatFile(filename, cur, format)
1730}
1731
1732#[no_mangle]
1740pub unsafe extern "C" fn xmlSaveFormatFileEnc(
1741 filename: *const c_char,
1742 cur: *mut _xmlDoc,
1743 encoding: *const c_char,
1744 format: c_int,
1745) -> c_int {
1746 if filename.is_null() || cur.is_null() {
1747 return -1;
1748 }
1749 crate::xml::tree::xmlSaveFormatFileEnc(filename, cur, encoding, format)
1750}
1751
1752#[no_mangle]
1767pub unsafe extern "C" fn xmlReadDoc(
1768 cur: *const xmlChar,
1769 URL: *const c_char,
1770 encoding: *const c_char,
1771 options: c_int,
1772) -> *mut _xmlDoc {
1773 if cur.is_null() {
1775 return ptr::null_mut();
1776 }
1777 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1778 if ctxt.is_null() {
1779 return ptr::null_mut();
1780 }
1781 let len = crate::xml::string::xml_strlen(cur);
1782 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
1783 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1784 (*ctxt).options = options;
1785 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1786 let doc = (*ctxt).myDoc;
1787 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1788 return doc;
1789 }
1790 let doc = (*ctxt).myDoc;
1791 if !doc.is_null() {
1792 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1793 }
1794 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1795 doc
1796}
1797
1798#[no_mangle]
1806pub unsafe extern "C" fn xmlReadFile(
1807 URL: *const c_char,
1808 encoding: *const c_char,
1809 options: c_int,
1810) -> *mut _xmlDoc {
1811 if URL.is_null() {
1813 return ptr::null_mut();
1814 }
1815 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1816 if ctxt.is_null() {
1817 return ptr::null_mut();
1818 }
1819 let input = match crate::xml::parser::helpers::input_from_file(URL) {
1820 Ok(input) => input,
1821 Err(_) => {
1822 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1823 return ptr::null_mut();
1824 }
1825 };
1826 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1827 (*ctxt).options = options;
1828 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1829 let doc = (*ctxt).myDoc;
1830 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1831 if options & 1 << 0 != 0 {
1835 return doc;
1836 }
1837 if !doc.is_null() {
1838 crate::xml::tree::free_doc(doc);
1839 }
1840 return ptr::null_mut();
1841 }
1842 let doc = (*ctxt).myDoc;
1843 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1844 doc
1845}
1846
1847#[no_mangle]
1856pub unsafe extern "C" fn xmlReadMemory(
1857 buffer: *const c_char,
1858 size: c_int,
1859 URL: *const c_char,
1860 encoding: *const c_char,
1861 options: c_int,
1862) -> *mut _xmlDoc {
1863 if buffer.is_null() || size <= 0 {
1865 return ptr::null_mut();
1866 }
1867 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1868 if ctxt.is_null() {
1869 return ptr::null_mut();
1870 }
1871 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
1872 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1873 (*ctxt).options = options;
1874 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1875 let doc = (*ctxt).myDoc;
1876 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1877 if options & 1 << 0 != 0 {
1881 return doc;
1882 }
1883 if !doc.is_null() {
1884 crate::xml::tree::free_doc(doc);
1885 }
1886 return ptr::null_mut();
1887 }
1888 let doc = (*ctxt).myDoc;
1889 if !doc.is_null() && !URL.is_null() {
1890 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1891 }
1892 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1893 doc
1894}
1895
1896#[no_mangle]
1902pub unsafe extern "C" fn xmlLoadCatalogs(catalogs: *const c_char) {
1903 if !catalogs.is_null() {
1904 crate::xml::catalog::load_catalog(catalogs);
1905 }
1906}
1907
1908#[no_mangle]
1914pub unsafe extern "C" fn xmlLoadCatalog(catalogs: *const c_char) -> *mut c_void {
1915 crate::xml::catalog::load_catalog(catalogs)
1916}
1917
1918#[no_mangle]
1926pub unsafe extern "C" fn xmlReadFd(
1927 fd: c_int,
1928 URL: *const c_char,
1929 encoding: *const c_char,
1930 options: c_int,
1931) -> *mut _xmlDoc {
1932 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1934 if ctxt.is_null() {
1935 return ptr::null_mut();
1936 }
1937 let mut buf = Vec::new();
1939 let mut tmp = [0u8; 4096];
1940 loop {
1941 let n = libc::read(fd, tmp.as_mut_ptr() as *mut c_void, tmp.len());
1942 if n <= 0 {
1943 break;
1944 }
1945 buf.extend_from_slice(&tmp[..n as usize]);
1946 }
1947 let input = crate::xml::parser::helpers::input_from_memory(
1948 buf.as_ptr() as *const c_char,
1949 buf.len() as c_int,
1950 );
1951 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1952 (*ctxt).options = options;
1953 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1954 let doc = (*ctxt).myDoc;
1955 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1956 return doc;
1957 }
1958 let doc = (*ctxt).myDoc;
1959 if !doc.is_null() && !URL.is_null() {
1960 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1961 }
1962 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1963 doc
1964}
1965
1966#[no_mangle]
1975pub unsafe extern "C" fn xmlReadIO(
1976 ioread: Option<xmlInputReadCallback>,
1977 ioclose: Option<xmlInputCloseCallback>,
1978 ioctx: *mut c_void,
1979 URL: *const c_char,
1980 encoding: *const c_char,
1981 options: c_int,
1982) -> *mut _xmlDoc {
1983 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1985 if ctxt.is_null() {
1986 return ptr::null_mut();
1987 }
1988 let input = crate::xml::parser::helpers::input_from_io(ioread, ioclose, ioctx);
1989 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1990 (*ctxt).options = options;
1991 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1992 let doc = (*ctxt).myDoc;
1993 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1994 return doc;
1995 }
1996 let doc = (*ctxt).myDoc;
1997 if !doc.is_null() && !URL.is_null() {
1998 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1999 }
2000 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2001 doc
2002}
2003
2004#[no_mangle]
2012pub unsafe extern "C" fn xmlSAXParseDoc(
2013 sax: *mut _xmlSAXHandler,
2014 cur: *const xmlChar,
2015 recovery: c_int,
2016) -> *mut _xmlDoc {
2017 if cur.is_null() {
2019 return ptr::null_mut();
2020 }
2021 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2022 if ctxt.is_null() {
2023 return ptr::null_mut();
2024 }
2025 if !sax.is_null() {
2026 (*ctxt).sax = sax;
2027 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2028 }
2029 if recovery != 0 {
2030 (*ctxt).recovery = 1;
2031 (*ctxt).options |= 1; }
2033 let len = crate::xml::string::xml_strlen(cur);
2034 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
2035 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2036 crate::xml::parser::helpers::parse_document(ctxt);
2037 let doc = (*ctxt).myDoc;
2038 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2039 doc
2040}
2041
2042#[no_mangle]
2050pub unsafe extern "C" fn xmlSAXParseFile(
2051 sax: *mut _xmlSAXHandler,
2052 filename: *const c_char,
2053 recovery: c_int,
2054) -> *mut _xmlDoc {
2055 if filename.is_null() {
2057 return ptr::null_mut();
2058 }
2059 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2060 if ctxt.is_null() {
2061 return ptr::null_mut();
2062 }
2063 if !sax.is_null() {
2064 (*ctxt).sax = sax;
2065 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2066 }
2067 if recovery != 0 {
2068 (*ctxt).recovery = 1;
2069 (*ctxt).options |= 1;
2070 }
2071 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2072 Ok(input) => input,
2073 Err(_) => {
2074 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2075 return ptr::null_mut();
2076 }
2077 };
2078 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2079 crate::xml::parser::helpers::parse_document(ctxt);
2080 let doc = (*ctxt).myDoc;
2081 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2082 doc
2083}
2084
2085#[no_mangle]
2094pub unsafe extern "C" fn xmlSAXParseMemory(
2095 sax: *mut _xmlSAXHandler,
2096 buffer: *const c_char,
2097 size: c_int,
2098 recovery: c_int,
2099) -> *mut _xmlDoc {
2100 if buffer.is_null() || size <= 0 {
2102 return ptr::null_mut();
2103 }
2104 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2105 if ctxt.is_null() {
2106 return ptr::null_mut();
2107 }
2108 if !sax.is_null() {
2109 (*ctxt).sax = sax;
2110 (*ctxt).userData = (*ctxt).sax as *mut c_void;
2111 }
2112 if recovery != 0 {
2113 (*ctxt).recovery = 1;
2114 (*ctxt).options |= 1;
2115 }
2116 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
2117 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2118 crate::xml::parser::helpers::parse_document(ctxt);
2119 let doc = (*ctxt).myDoc;
2120 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2121 doc
2122}
2123
2124#[no_mangle]
2133pub unsafe extern "C" fn xmlSAXUserParseFile(
2134 sax: *mut _xmlSAXHandler,
2135 user_data: *mut c_void,
2136 filename: *const c_char,
2137) -> c_int {
2138 if filename.is_null() {
2140 return -1;
2141 }
2142 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2143 if ctxt.is_null() {
2144 return -1;
2145 }
2146 if !sax.is_null() {
2147 (*ctxt).sax = sax;
2148 }
2149 (*ctxt).userData = if !user_data.is_null() {
2150 user_data
2151 } else {
2152 ctxt as *mut c_void
2153 };
2154 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2155 Ok(input) => input,
2156 Err(_) => {
2157 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2158 return -1;
2159 }
2160 };
2161 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2162 let ret = crate::xml::parser::helpers::parse_document(ctxt);
2163 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2164 ret
2165}
2166
2167#[no_mangle]
2176pub unsafe extern "C" fn xmlSAXUserParseMemory(
2177 sax: *mut _xmlSAXHandler,
2178 user_data: *mut c_void,
2179 buffer: *const c_char,
2180 size: c_int,
2181) -> c_int {
2182 if buffer.is_null() || size <= 0 {
2184 return -1;
2185 }
2186 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2187 if ctxt.is_null() {
2188 return -1;
2189 }
2190 if !sax.is_null() {
2191 (*ctxt).sax = sax;
2192 }
2193 (*ctxt).userData = if !user_data.is_null() {
2194 user_data
2195 } else {
2196 ctxt as *mut c_void
2197 };
2198 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
2199 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2200 let ret = crate::xml::parser::helpers::parse_document(ctxt);
2201 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2202 ret
2203}
2204
2205#[no_mangle]
2213pub unsafe extern "C" fn xmlParseDoc(cur: *const xmlChar) -> *mut _xmlDoc {
2214 if cur.is_null() {
2216 return ptr::null_mut();
2217 }
2218 xmlReadDoc(cur, ptr::null(), ptr::null(), 0)
2219}
2220
2221#[no_mangle]
2229pub unsafe extern "C" fn xmlParseFile(filename: *const c_char) -> *mut _xmlDoc {
2230 if filename.is_null() {
2232 return ptr::null_mut();
2233 }
2234 xmlReadFile(filename, ptr::null(), 0)
2235}
2236
2237#[no_mangle]
2245pub unsafe extern "C" fn xmlParseMemory(buffer: *const c_char, size: c_int) -> *mut _xmlDoc {
2246 if buffer.is_null() || size <= 0 {
2248 return ptr::null_mut();
2249 }
2250 xmlReadMemory(buffer, size, ptr::null(), ptr::null(), 0)
2251}
2252
2253#[no_mangle]
2261pub unsafe extern "C" fn xmlCreateFileParserCtxt(filename: *const c_char) -> *mut _xmlParserCtxt {
2262 if filename.is_null() {
2264 return ptr::null_mut();
2265 }
2266 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2267 if ctxt.is_null() {
2268 return ptr::null_mut();
2269 }
2270 let input = match crate::xml::parser::helpers::input_from_file(filename) {
2271 Ok(input) => input,
2272 Err(_) => {
2273 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2274 return ptr::null_mut();
2275 }
2276 };
2277 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2278 ctxt
2279}
2280
2281#[no_mangle]
2289pub unsafe extern "C" fn xmlCreateDocParserCtxt(cur: *const xmlChar) -> *mut _xmlParserCtxt {
2290 if cur.is_null() {
2292 return ptr::null_mut();
2293 }
2294 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
2295 if ctxt.is_null() {
2296 return ptr::null_mut();
2297 }
2298 let len = crate::xml::string::xml_strlen(cur);
2299 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
2300 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
2301 ctxt
2302}
2303
2304#[no_mangle]
2312pub unsafe extern "C" fn xmlParseDocument(ctxt: *mut _xmlParserCtxt) -> c_int {
2313 if ctxt.is_null() {
2315 return -1;
2316 }
2317 crate::xml::parser::helpers::parse_document(ctxt)
2318}
2319
2320#[no_mangle]
2328pub unsafe extern "C" fn xmlFreeParserCtxt(ctxt: *mut _xmlParserCtxt) {
2329 if ctxt.is_null() {
2330 return;
2331 }
2332 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
2333}
2334
2335#[no_mangle]
2343pub unsafe extern "C" fn xmlCtxtUseOptions(ctxt: *mut _xmlParserCtxt, options: c_int) -> c_int {
2344 if ctxt.is_null() {
2345 return -1;
2346 }
2347 unsafe {
2349 (*ctxt).options = options;
2350 }
2351 0
2352}
2353
2354#[no_mangle]
2363pub unsafe extern "C" fn xmlParseChunk(
2364 ctxt: *mut _xmlParserCtxt,
2365 chunk: *const c_char,
2366 size: c_int,
2367 terminate: c_int,
2368) -> c_int {
2369 if ctxt.is_null() {
2372 return -1;
2373 }
2374 crate::xml::parser::helpers::parse_chunk(ctxt, chunk, size, terminate)
2375}
2376
2377#[no_mangle]
2385pub unsafe extern "C" fn xmlParserInputBufferCreateMem(
2386 buffer: *const c_char,
2387 size: c_int,
2388 enc: c_int,
2389) -> *mut _xmlParserInputBuffer {
2390 if buffer.is_null() || size <= 0 {
2392 return ptr::null_mut();
2393 }
2394 crate::xml::parser::helpers::alloc_parser_input_buffer()
2395}
2396
2397#[no_mangle]
2405pub unsafe extern "C" fn xmlParserInputBufferCreateFilename(
2406 URI: *const c_char,
2407 enc: c_int,
2408) -> *mut _xmlParserInputBuffer {
2409 if URI.is_null() {
2411 return ptr::null_mut();
2412 }
2413 crate::xml::parser::helpers::alloc_parser_input_buffer()
2414}
2415
2416#[no_mangle]
2426pub unsafe extern "C" fn xmlParserInputBufferCreateIO(
2427 ioread: Option<xmlInputReadCallback>,
2428 ioclose: Option<xmlInputCloseCallback>,
2429 ioctx: *mut c_void,
2430 enc: c_int,
2431) -> *mut _xmlParserInputBuffer {
2432 let buf = crate::xml::parser::helpers::alloc_parser_input_buffer();
2434 if !buf.is_null() {
2435 (*buf).readcallback = ioread;
2436 (*buf).closecallback = ioclose;
2437 (*buf).context = ioctx;
2438 }
2439 buf
2440}
2441
2442#[no_mangle]
2450pub unsafe extern "C" fn xmlFreeParserInputBuffer(buf: *mut _xmlParserInputBuffer) {
2451 if buf.is_null() {
2452 return;
2453 }
2454 crate::xml::parser::helpers::free_parser_input_buffer(buf);
2455}
2456
2457#[no_mangle]
2465pub unsafe extern "C" fn xmlNewInputFromFile(
2466 ctxt: *mut _xmlParserCtxt,
2467 filename: *const c_char,
2468) -> *mut _xmlParserInput {
2469 if filename.is_null() {
2474 return ptr::null_mut();
2475 }
2476 crate::xml::parser::helpers::alloc_parser_input_buffer() as *mut _xmlParserInput
2477}
2478
2479#[no_mangle]
2487pub unsafe extern "C" fn xmlFreeInputStream(input: *mut _xmlParserInput) {
2488 if input.is_null() {
2489 return;
2490 }
2491 crate::xml::parser::helpers::free_parser_input(input);
2492}
2493
2494#[no_mangle]
2508pub unsafe extern "C" fn xmlOutputBufferCreateFilename(
2509 URI: *const c_char,
2510 encoder: *mut c_void,
2511 compression: c_int,
2512) -> *mut _xmlOutputBuffer {
2513 let _ = compression;
2514 if URI.is_null() {
2515 return ptr::null_mut();
2516 }
2517 crate::xml::io::output_buffer_create_filename(
2518 URI,
2519 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2520 0,
2521 )
2522}
2523
2524#[no_mangle]
2533pub unsafe extern "C" fn xmlOutputBufferCreateFd(
2534 fd: c_int,
2535 encoder: *mut c_void,
2536) -> *mut _xmlOutputBuffer {
2537 if fd < 0 {
2538 return ptr::null_mut();
2539 }
2540 crate::xml::io::output_buffer_create_fd(
2541 fd,
2542 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2543 )
2544}
2545
2546#[no_mangle]
2556pub unsafe extern "C" fn xmlOutputBufferCreateIO(
2557 iowrite: Option<xmlOutputWriteCallback>,
2558 ioclose: Option<xmlOutputCloseCallback>,
2559 ioctx: *mut c_void,
2560 encoder: *mut c_void,
2561) -> *mut _xmlOutputBuffer {
2562 crate::xml::io::output_buffer_create_io(
2563 iowrite,
2564 ioclose,
2565 ioctx,
2566 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2567 )
2568}
2569
2570#[no_mangle]
2578pub unsafe extern "C" fn xmlOutputBufferClose(out: *mut _xmlOutputBuffer) -> c_int {
2579 if out.is_null() {
2580 return -1;
2581 }
2582 crate::xml::io::output_buffer_close(out)
2583}
2584
2585#[no_mangle]
2593pub unsafe extern "C" fn xmlOutputBufferFlush(out: *mut _xmlOutputBuffer) -> c_int {
2594 if out.is_null() {
2595 return -1;
2596 }
2597 crate::xml::io::output_buffer_flush(out)
2598}
2599
2600#[no_mangle]
2608pub unsafe extern "C" fn xmlOutputBufferWrite(
2609 out: *mut _xmlOutputBuffer,
2610 len: c_int,
2611 data: *const c_char,
2612) -> c_int {
2613 if out.is_null() || data.is_null() || len <= 0 {
2614 return -1;
2615 }
2616 crate::xml::io::output_buffer_write(out, len, data)
2617}
2618
2619#[no_mangle]
2627pub unsafe extern "C" fn xmlOutputBufferWriteString(
2628 out: *mut _xmlOutputBuffer,
2629 str: *const c_char,
2630) -> c_int {
2631 if str.is_null() {
2632 return 0;
2633 }
2634 unsafe { xmlOutputBufferWrite(out, xmlStrlen(str as *const xmlChar), str) }
2635}
2636
2637#[no_mangle]
2649pub extern "C" fn xmlDictCreate() -> *mut c_void {
2650 ptr::null_mut()
2652}
2653
2654#[no_mangle]
2662pub extern "C" fn xmlDictCreateSub(_sub: *mut c_void) -> *mut c_void {
2663 ptr::null_mut()
2665}
2666
2667#[no_mangle]
2679pub unsafe extern "C" fn xmlDictLookup(
2680 dict: *mut c_void,
2681 name: *const xmlChar,
2682 len: c_int,
2683) -> *const xmlChar {
2684 name
2686}
2687
2688#[no_mangle]
2696pub unsafe extern "C" fn xmlDictExists(
2697 dict: *mut c_void,
2698 name: *const xmlChar,
2699 len: c_int,
2700) -> *const xmlChar {
2701 ptr::null()
2703}
2704
2705#[no_mangle]
2713pub extern "C" fn xmlDictSize(dict: *const c_void) -> c_uint {
2714 0
2716}
2717
2718#[no_mangle]
2726pub extern "C" fn xmlDictFree(_dict: *mut c_void) {
2727 }
2729
2730#[no_mangle]
2738pub extern "C" fn xmlDictSetLimit(_dict: *mut c_void, _limit: c_uint) -> c_uint {
2739 0
2741}
2742
2743#[no_mangle]
2751pub extern "C" fn xmlDictGetUsage(_dict: *const c_void) -> c_uint {
2752 0
2754}
2755
2756#[no_mangle]
2768pub extern "C" fn xmlHashCreate(_size: c_int) -> *mut c_void {
2769 ptr::null_mut()
2771}
2772
2773#[no_mangle]
2781pub extern "C" fn xmlHashCreateDict(_size: c_int, _dict: *mut c_void) -> *mut c_void {
2782 ptr::null_mut()
2784}
2785
2786#[no_mangle]
2794pub extern "C" fn xmlHashFree(
2795 _table: *mut c_void,
2796 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2797) {
2798 }
2800
2801#[no_mangle]
2809pub unsafe extern "C" fn xmlHashAddEntry(
2810 _table: *mut c_void,
2811 _name: *const xmlChar,
2812 _userdata: *mut c_void,
2813) -> c_int {
2814 0
2816}
2817
2818#[no_mangle]
2827pub unsafe extern "C" fn xmlHashAddEntry2(
2828 _table: *mut c_void,
2829 _name: *const xmlChar,
2830 _name2: *const xmlChar,
2831 _userdata: *mut c_void,
2832) -> c_int {
2833 0
2835}
2836
2837#[no_mangle]
2846pub unsafe extern "C" fn xmlHashAddEntry3(
2847 _table: *mut c_void,
2848 _name: *const xmlChar,
2849 _name2: *const xmlChar,
2850 _name3: *const xmlChar,
2851 _userdata: *mut c_void,
2852) -> c_int {
2853 0
2855}
2856
2857#[no_mangle]
2866pub unsafe extern "C" fn xmlHashUpdateEntry(
2867 _table: *mut c_void,
2868 _name: *const xmlChar,
2869 _userdata: *mut c_void,
2870 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2871) -> c_int {
2872 0
2874}
2875
2876#[no_mangle]
2878pub unsafe extern "C" fn xmlHashUpdateEntry2(
2879 _table: *mut c_void,
2880 _name: *const xmlChar,
2881 _name2: *const xmlChar,
2882 _userdata: *mut c_void,
2883 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2884) -> c_int {
2885 0
2887}
2888
2889#[no_mangle]
2891pub unsafe extern "C" fn xmlHashUpdateEntry3(
2892 _table: *mut c_void,
2893 _name: *const xmlChar,
2894 _name2: *const xmlChar,
2895 _name3: *const xmlChar,
2896 _userdata: *mut c_void,
2897 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2898) -> c_int {
2899 0
2901}
2902
2903#[no_mangle]
2911pub unsafe extern "C" fn xmlHashLookup(_table: *mut c_void, _name: *const xmlChar) -> *mut c_void {
2912 ptr::null_mut()
2914}
2915
2916#[no_mangle]
2918pub unsafe extern "C" fn xmlHashLookup2(
2919 _table: *mut c_void,
2920 _name: *const xmlChar,
2921 _name2: *const xmlChar,
2922) -> *mut c_void {
2923 ptr::null_mut()
2925}
2926
2927#[no_mangle]
2929pub unsafe extern "C" fn xmlHashLookup3(
2930 _table: *mut c_void,
2931 _name: *const xmlChar,
2932 _name2: *const xmlChar,
2933 _name3: *const xmlChar,
2934) -> *mut c_void {
2935 ptr::null_mut()
2937}
2938
2939#[no_mangle]
2947pub extern "C" fn xmlHashSize(_table: *mut c_void) -> c_int {
2948 0
2950}
2951
2952#[no_mangle]
2961pub unsafe extern "C" fn xmlHashRemoveEntry(
2962 _table: *mut c_void,
2963 _name: *const xmlChar,
2964 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2965) -> c_int {
2966 0
2968}
2969
2970#[no_mangle]
2972pub unsafe extern "C" fn xmlHashRemoveEntry2(
2973 _table: *mut c_void,
2974 _name: *const xmlChar,
2975 _name2: *const xmlChar,
2976 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2977) -> c_int {
2978 0
2980}
2981
2982#[no_mangle]
2984pub unsafe extern "C" fn xmlHashRemoveEntry3(
2985 _table: *mut c_void,
2986 _name: *const xmlChar,
2987 _name2: *const xmlChar,
2988 _name3: *const xmlChar,
2989 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2990) -> c_int {
2991 0
2993}
2994
2995#[no_mangle]
3003pub extern "C" fn xmlHashScan(
3004 _table: *mut c_void,
3005 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void)>,
3006 _data: *mut c_void,
3007) {
3008 }
3010
3011#[no_mangle]
3013pub extern "C" fn xmlHashScanFull(
3014 _table: *mut c_void,
3015 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void, *mut c_void)>,
3016 _data: *mut c_void,
3017) {
3018 }
3020
3021#[no_mangle]
3029pub extern "C" fn xmlHashCopy(
3030 _table: *mut c_void,
3031 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar) -> *mut c_void>,
3032) -> *mut c_void {
3033 ptr::null_mut()
3035}
3036
3037#[no_mangle]
3050pub extern "C" fn xmlListCreate(
3051 _deallocator: Option<unsafe extern "C" fn(*mut c_void)>,
3052 _compare: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
3053) -> *mut c_void {
3054 ptr::null_mut()
3056}
3057
3058#[no_mangle]
3066pub extern "C" fn xmlListDelete(_list: *mut c_void) {
3067 }
3069
3070#[no_mangle]
3078pub extern "C" fn xmlListSearch(_list: *mut c_void, _data: *mut c_void) -> *mut c_void {
3079 ptr::null_mut()
3081}
3082
3083#[no_mangle]
3091pub extern "C" fn xmlListWalk(
3092 _list: *mut c_void,
3093 _walker: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
3094 _data: *mut c_void,
3095) {
3096 }
3098
3099#[no_mangle]
3107pub extern "C" fn xmlListPushBack(_list: *mut c_void, _data: *mut c_void) -> c_int {
3108 0
3110}
3111
3112#[no_mangle]
3120pub extern "C" fn xmlListPushFront(_list: *mut c_void, _data: *mut c_void) -> c_int {
3121 0
3123}
3124
3125#[no_mangle]
3127pub extern "C" fn xmlListPopBack(_list: *mut c_void) {
3128 }
3130
3131#[no_mangle]
3133pub extern "C" fn xmlListPopFront(_list: *mut c_void) {
3134 }
3136
3137#[no_mangle]
3145pub extern "C" fn xmlListInsert(_list: *mut c_void, _data: *mut c_void) -> c_int {
3146 0
3148}
3149
3150#[no_mangle]
3152pub extern "C" fn xmlListAppend(_list: *mut c_void, _data: *mut c_void) -> c_int {
3153 0
3155}
3156
3157#[no_mangle]
3159pub extern "C" fn xmlListRemoveFirst(_list: *mut c_void, _data: *mut c_void) -> c_int {
3160 0
3162}
3163
3164#[no_mangle]
3166pub extern "C" fn xmlListRemoveLast(_list: *mut c_void, _data: *mut c_void) -> c_int {
3167 0
3169}
3170
3171#[no_mangle]
3173pub extern "C" fn xmlListRemoveAll(_list: *mut c_void, _data: *mut c_void) -> c_int {
3174 0
3176}
3177
3178#[no_mangle]
3180pub extern "C" fn xmlListClear(_list: *mut c_void) {
3181 }
3183
3184#[no_mangle]
3192pub extern "C" fn xmlListEmpty(_list: *mut c_void) -> c_int {
3193 1
3195}
3196
3197#[no_mangle]
3205pub extern "C" fn xmlListFront(_list: *mut c_void) -> *mut c_void {
3206 ptr::null_mut()
3208}
3209
3210#[no_mangle]
3218pub extern "C" fn xmlListBack(_list: *mut c_void) -> *mut c_void {
3219 ptr::null_mut()
3221}
3222
3223#[no_mangle]
3231pub extern "C" fn xmlListSize(_list: *mut c_void) -> c_int {
3232 0
3234}
3235
3236#[no_mangle]
3238pub extern "C" fn xmlListSort(_list: *mut c_void) {
3239 }
3241
3242#[no_mangle]
3244pub extern "C" fn xmlListReverse(_list: *mut c_void) {
3245 }
3247
3248#[no_mangle]
3250pub extern "C" fn xmlListReverseSplice(_list: *mut c_void, _list2: *mut c_void) {
3251 }
3253
3254#[no_mangle]
3256pub extern "C" fn xmlListMerge(_list: *mut c_void, _list2: *mut c_void) {
3257 }
3259
3260#[no_mangle]
3272pub extern "C" fn xmlBufferCreate() -> *mut _xmlBuffer {
3273 crate::xml::io::buf_create(-1)
3274}
3275
3276#[no_mangle]
3284pub extern "C" fn xmlBufferCreateSize(size: usize) -> *mut _xmlBuffer {
3285 crate::xml::io::buf_create(size as c_int)
3286}
3287
3288#[no_mangle]
3296pub extern "C" fn xmlBufferCreateStatic(mem: *mut c_void, size: usize) -> *mut _xmlBuffer {
3297 if mem.is_null() || size == 0 {
3298 return ptr::null_mut();
3299 }
3300 crate::xml::io::buf_create_static(mem as *const xmlChar, size as c_int)
3301}
3302
3303#[no_mangle]
3311pub extern "C" fn xmlBufferFree(buf: *mut _xmlBuffer) {
3312 crate::xml::io::buf_free(buf)
3313}
3314
3315#[no_mangle]
3323pub extern "C" fn xmlBufferEmpty(buf: *mut _xmlBuffer) {
3324 if buf.is_null() {
3325 return;
3326 }
3327 unsafe {
3328 if !(*buf).content.is_null() {
3329 *(*buf).content = 0;
3330 }
3331 (*buf).use_ = 0;
3332 }
3333}
3334
3335#[no_mangle]
3343pub extern "C" fn xmlBufferContent(buf: *const _xmlBuffer) -> *mut xmlChar {
3344 crate::xml::io::buf_content(buf as *mut _xmlBuffer)
3345}
3346
3347#[no_mangle]
3355pub extern "C" fn xmlBufferLength(buf: *const _xmlBuffer) -> c_int {
3356 crate::xml::io::buf_length(buf as *mut _xmlBuffer)
3357}
3358
3359#[no_mangle]
3367pub unsafe extern "C" fn xmlBufferAdd(
3368 buf: *mut _xmlBuffer,
3369 str: *const xmlChar,
3370 len: c_int,
3371) -> c_int {
3372 crate::xml::io::buf_add(buf, str, len)
3373}
3374
3375#[no_mangle]
3383pub unsafe extern "C" fn xmlBufferAddHead(
3384 buf: *mut _xmlBuffer,
3385 str: *const xmlChar,
3386 len: c_int,
3387) -> c_int {
3388 crate::xml::io::buf_add_head(buf, str, len)
3389}
3390
3391#[no_mangle]
3399pub unsafe extern "C" fn xmlBufferCat(buf: *mut _xmlBuffer, str: *const xmlChar) -> c_int {
3400 if str.is_null() {
3401 return -1;
3402 }
3403 let len = crate::xml::string::xml_strlen(str) as c_int;
3404 crate::xml::io::buf_add(buf, str, len)
3405}
3406
3407#[no_mangle]
3416pub extern "C" fn xmlBufferSetAllocationScheme(buf: *mut _xmlBuffer, scheme: c_int) {
3417 if buf.is_null() {
3418 return;
3419 }
3420 unsafe {
3421 (*buf).alloc = scheme;
3422 }
3423}
3424
3425#[no_mangle]
3433pub extern "C" fn xmlBufferShrink(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3434 if buf.is_null() || len <= 0 {
3435 return 0;
3436 }
3437 unsafe {
3438 let b = &mut *buf;
3439 let shrink_len = (len as c_uint).min(b.use_);
3440 if shrink_len > 0 {
3441 let remaining = b.use_ - shrink_len;
3442 if remaining > 0 {
3443 core::ptr::copy(
3444 b.content.add(shrink_len as usize),
3445 b.content,
3446 remaining as usize,
3447 );
3448 }
3449 *b.content.add(remaining as usize) = 0;
3450 b.use_ = remaining;
3451 }
3452 }
3453 len
3454}
3455
3456#[no_mangle]
3464pub extern "C" fn xmlBufferGrow(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3465 if buf.is_null() || len <= 0 {
3466 return 0;
3467 }
3468 let cur_use = unsafe { (*buf).use_ };
3469 let new_size = cur_use + len as c_uint + 1;
3470 crate::xml::io::buf_grow(buf, new_size)
3471}
3472
3473#[no_mangle]
3481pub extern "C" fn xmlBufferReserve(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3482 xmlBufferGrow(buf, len)
3483}
3484
3485#[no_mangle]
3493pub extern "C" fn xmlBufferDetach(buf: *mut _xmlBuffer) -> *mut xmlChar {
3494 if buf.is_null() {
3495 return ptr::null_mut();
3496 }
3497 unsafe {
3498 let content = (*buf).content;
3499 (*buf).content = ptr::null_mut();
3500 (*buf).use_ = 0;
3501 (*buf).size = 0;
3502 content
3503 }
3504}
3505
3506#[no_mangle]
3518pub extern "C" fn xmlGetCharEncoding(name: *const c_char) -> c_int {
3519 if name.is_null() {
3520 return 0; }
3522 let name_bytes = unsafe {
3523 let len = libc::strlen(name);
3524 core::slice::from_raw_parts(name as *const u8, len)
3525 };
3526 crate::xml::encoding::encoding_from_name(name_bytes) as c_int
3527}
3528
3529#[no_mangle]
3537pub extern "C" fn xmlFindCharEncodingHandler(name: *const c_char) -> *mut c_void {
3538 if name.is_null() {
3539 return ptr::null_mut();
3540 }
3541 crate::xml::encoding::find_encoding_handler(name as *const xmlChar) as *mut c_void
3542}
3543
3544#[no_mangle]
3552pub extern "C" fn xmlCharEncCloseFunc(handler: *mut c_void) -> c_int {
3553 if handler.is_null() {
3554 return -1;
3555 }
3556 unsafe {
3558 let h = handler as *mut crate::abi::structs::_xmlCharEncodingHandler;
3559 if !(*h).name.is_null() {
3560 crate::abi::allocator::xmlFree((*h).name as *mut c_void);
3561 }
3562 crate::abi::allocator::xmlFree(handler);
3563 }
3564 0
3565}
3566
3567#[no_mangle]
3575pub unsafe extern "C" fn xmlCharEncInput(input: *mut _xmlParserInputBuffer, _to: c_int) -> c_int {
3576 if input.is_null() {
3577 return -1;
3578 }
3579 let handler = (*input).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3580 if handler.is_null() {
3581 return -1;
3582 }
3583 let raw = (*input).raw as *mut crate::abi::structs::_xmlBuffer;
3584 let buf = (*input).buffer as *mut crate::abi::structs::_xmlBuffer;
3585 if raw.is_null() || buf.is_null() {
3586 return -1;
3587 }
3588 crate::xml::encoding::char_enc_in(handler, buf, raw)
3589}
3590
3591#[no_mangle]
3599pub unsafe extern "C" fn xmlCharEncOutput(output: *mut _xmlOutputBuffer, _to: c_int) -> c_int {
3600 if output.is_null() {
3601 return -1;
3602 }
3603 let handler = (*output).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3604 if handler.is_null() {
3605 return -1;
3606 }
3607 let buf = (*output).buffer as *mut crate::abi::structs::_xmlBuffer;
3608 let conv = (*output).conv as *mut crate::abi::structs::_xmlBuffer;
3609 if buf.is_null() || conv.is_null() {
3610 return -1;
3611 }
3612 crate::xml::encoding::char_enc_out(handler, conv, buf)
3613}
3614
3615#[no_mangle]
3627pub unsafe extern "C" fn xmlParseURI(str: *const c_char) -> *mut c_void {
3628 crate::xml::uri::xmlParseURI(str)
3629}
3630
3631#[no_mangle]
3639pub unsafe extern "C" fn xmlParseURIRaw(str: *const c_char, raw: c_int) -> *mut c_void {
3640 let _ = raw;
3641 crate::xml::uri::xmlParseURI(str)
3642}
3643
3644#[no_mangle]
3652pub unsafe extern "C" fn xmlFreeURI(uri: *mut c_void) {
3653 crate::xml::uri::xmlFreeURI(uri)
3654}
3655
3656#[no_mangle]
3664pub extern "C" fn xmlCreateURI() -> *mut c_void {
3665 crate::xml::uri::xmlCreateURI()
3666}
3667
3668#[no_mangle]
3676pub unsafe extern "C" fn xmlSaveUri(uri: *mut c_void) -> *mut xmlChar {
3677 crate::xml::uri::xmlSaveUri(uri)
3678}
3679
3680#[no_mangle]
3688pub unsafe extern "C" fn xmlURIEscapeStr(
3689 str: *const xmlChar,
3690 list: *const xmlChar,
3691) -> *mut xmlChar {
3692 crate::xml::uri::xmlURIEscapeStr(str, list)
3693}
3694
3695#[no_mangle]
3703pub unsafe extern "C" fn xmlURIUnescapeString(
3704 str: *const c_char,
3705 len: c_int,
3706 target: *mut c_char,
3707) -> *mut c_char {
3708 crate::xml::uri::xmlURIUnescapeString(str, len, target)
3709}
3710
3711unsafe fn xpath_to_object(val: XPathValue) -> *mut _xmlXPathObject {
3726 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
3727 if obj.is_null() {
3728 return ptr::null_mut();
3729 }
3730 match val {
3731 XPathValue::NodeSet(ns) => {
3732 (*obj).type_ = xmlXPathObjectType::XPATH_NODESET as c_int;
3733 (*obj).nodesetval = ns.to_raw() as *mut c_void;
3734 }
3735 XPathValue::Boolean(b) => {
3736 (*obj).type_ = xmlXPathObjectType::XPATH_BOOLEAN as c_int;
3737 (*obj).boolval = if b { 1 } else { 0 };
3738 }
3739 XPathValue::Number(n) => {
3740 (*obj).type_ = xmlXPathObjectType::XPATH_NUMBER as c_int;
3741 (*obj).floatval = n;
3742 }
3743 XPathValue::String(s) => {
3744 (*obj).type_ = xmlXPathObjectType::XPATH_STRING as c_int;
3745 let bytes = s.as_bytes();
3746 let len = bytes.len();
3747 let buf = xmlMalloc(len + 1) as *mut xmlChar;
3748 if !buf.is_null() {
3749 ptr::copy_nonoverlapping(bytes.as_ptr(), buf, len);
3750 *buf.add(len) = 0; }
3752 (*obj).stringval = buf;
3753 }
3754 }
3755 obj
3756}
3757
3758unsafe fn object_to_xpathvalue(obj: *mut _xmlXPathObject) -> XPathValue {
3765 let typ = (*obj).type_;
3766 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3767 let ns_ptr = (*obj).nodesetval as *mut _xmlNodeSet;
3768 if ns_ptr.is_null() {
3769 return XPathValue::NodeSet(NodeSet::new());
3770 }
3771 let node_nr = (*ns_ptr).nodeNr;
3772 let node_tab = (*ns_ptr).nodeTab;
3773 let mut ns = NodeSet::new();
3774 if !node_tab.is_null() {
3775 for i in 0..node_nr as isize {
3776 let node = *node_tab.add(i as usize);
3777 ns.push(node);
3778 }
3779 }
3780 XPathValue::NodeSet(ns)
3781 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
3782 XPathValue::Boolean((*obj).boolval != 0)
3783 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
3784 XPathValue::Number((*obj).floatval)
3785 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3786 let s_ptr = (*obj).stringval;
3787 if s_ptr.is_null() {
3788 XPathValue::String(String::new())
3789 } else {
3790 let s = CStr::from_ptr(s_ptr as *const c_char)
3791 .to_string_lossy()
3792 .into_owned();
3793 XPathValue::String(s)
3794 }
3795 } else if typ == xmlXPathObjectType::XPATH_XSLT_TREE as c_int {
3796 let frag_doc = (*obj).nodesetval as *mut _xmlDoc;
3801 if frag_doc.is_null() {
3802 XPathValue::NodeSet(NodeSet::new())
3803 } else {
3804 let mut ns = NodeSet::new();
3805 ns.push(frag_doc as *mut _xmlNode);
3806 XPathValue::NodeSet(ns)
3807 }
3808 } else {
3809 XPathValue::Boolean(false)
3811 }
3812}
3813
3814pub unsafe fn object_to_xpathvalue_pub(obj: *mut _xmlXPathObject) -> XPathValue {
3821 object_to_xpathvalue(obj)
3822}
3823
3824static COMPILED_EXPRS: Lazy<Mutex<HashMap<u64, Box<CompiledExpr>>>> =
3830 Lazy::new(|| Mutex::new(HashMap::new()));
3831static NEXT_COMPILED_KEY: Lazy<Mutex<u64>> = Lazy::new(|| Mutex::new(1));
3832
3833type CXPathFunc = unsafe extern "C" fn(*mut c_void, c_int);
3843
3844#[derive(Clone, Copy, PartialEq, Eq, Hash)]
3847struct SendSyncPtr(*mut c_void);
3848unsafe impl Send for SendSyncPtr {}
3849unsafe impl Sync for SendSyncPtr {}
3850
3851static C_FUNCTIONS: Lazy<Mutex<HashMap<(SendSyncPtr, String), CXPathFunc>>> =
3852 Lazy::new(|| Mutex::new(HashMap::new()));
3853
3854fn c_func_stub(_ctx: &mut XPathContext, _args: &[XPathValue]) -> Result<XPathValue, String> {
3859 Err(
3860 "C extension function cannot be called from Rust evaluator without a parser-context bridge"
3861 .to_string(),
3862 )
3863}
3864
3865#[no_mangle]
3878pub unsafe extern "C" fn xmlXPathNewContext(doc: *mut _xmlDoc) -> *mut _xmlXPathContext {
3879 let ctxt = xmlMallocZero(size_of::<_xmlXPathContext>()) as *mut _xmlXPathContext;
3880 if ctxt.is_null() {
3881 return ptr::null_mut();
3882 }
3883
3884 (*ctxt).doc = doc;
3886 (*ctxt).node = ptr::null_mut();
3887 (*ctxt).contextSize = 1;
3888 (*ctxt).proximityPosition = 1;
3889
3890 let internal = Box::new(XPathContext::new(doc));
3892 (*ctxt).extra = Box::into_raw(internal) as *mut c_void;
3893
3894 ctxt
3895}
3896
3897#[no_mangle]
3905pub unsafe extern "C" fn xmlXPathFreeContext(ctxt: *mut _xmlXPathContext) {
3906 if ctxt.is_null() {
3907 return;
3908 }
3909 if !(*ctxt).extra.is_null() {
3911 let _ = Box::from_raw((*ctxt).extra as *mut XPathContext);
3912 (*ctxt).extra = ptr::null_mut();
3913 }
3914 xmlFree(ctxt as *mut c_void);
3916}
3917
3918#[no_mangle]
3927pub unsafe extern "C" fn xmlXPathEvalExpression(
3928 str_: *const xmlChar,
3929 ctxt: *mut _xmlXPathContext,
3930) -> *mut _xmlXPathObject {
3931 if str_.is_null() || ctxt.is_null() {
3932 return ptr::null_mut();
3933 }
3934 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
3935 Ok(s) => s,
3936 Err(_) => return ptr::null_mut(),
3937 };
3938 let internal = (*ctxt).extra as *mut XPathContext;
3939 if internal.is_null() {
3940 return ptr::null_mut();
3941 }
3942 let internal = &mut *internal;
3943
3944 match crate::xml::xpath::evaluate_str(expr_str, internal) {
3945 Some(val) => xpath_to_object(val),
3946 None => {
3947 if internal.error.is_none() {
3952 internal.set_error("Invalid expression");
3953 }
3954 ptr::null_mut()
3955 }
3956 }
3957}
3958
3959#[no_mangle]
3967pub unsafe extern "C" fn xmlXPathEval(
3968 str_: *const xmlChar,
3969 ctxt: *mut _xmlXPathContext,
3970) -> *mut _xmlXPathObject {
3971 xmlXPathEvalExpression(str_, ctxt)
3972}
3973
3974#[no_mangle]
3985pub unsafe extern "C" fn xmlXPathFreeObject(obj: *mut _xmlXPathObject) {
3986 if obj.is_null() {
3987 return;
3988 }
3989 let typ = (*obj).type_;
3990 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3992 if !(*obj).stringval.is_null() {
3993 xmlFree((*obj).stringval as *mut c_void);
3994 (*obj).stringval = ptr::null_mut();
3995 }
3996 }
3997 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3999 let ns = (*obj).nodesetval as *mut _xmlNodeSet;
4000 if !ns.is_null() {
4001 if !(*ns).nodeTab.is_null() {
4002 xmlFree((*ns).nodeTab as *mut c_void);
4003 }
4004 xmlFree(ns as *mut c_void);
4005 }
4006 (*obj).nodesetval = ptr::null_mut();
4007 }
4008 xmlFree(obj as *mut c_void);
4009}
4010
4011#[no_mangle]
4023pub unsafe extern "C" fn xmlXPathObjectCopy(val: *mut _xmlXPathObject) -> *mut _xmlXPathObject {
4024 if val.is_null() {
4025 return ptr::null_mut();
4026 }
4027 let typ = (*val).type_;
4028 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
4029 if obj.is_null() {
4030 return ptr::null_mut();
4031 }
4032 (*obj).type_ = typ;
4033 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
4034 let src_ns = (*val).nodesetval as *mut _xmlNodeSet;
4035 if !src_ns.is_null() {
4036 let nr = (*src_ns).nodeNr;
4037 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
4038 if ns.is_null() {
4039 xmlFree(obj as *mut c_void);
4040 return ptr::null_mut();
4041 }
4042 (*ns).nodeNr = nr;
4043 (*ns).nodeMax = nr;
4044 if nr > 0 && !(*src_ns).nodeTab.is_null() {
4045 let tab = xmlMalloc((nr as usize) * core::mem::size_of::<*mut _xmlNode>())
4046 as *mut *mut _xmlNode;
4047 if tab.is_null() {
4048 xmlFree(ns as *mut c_void);
4049 xmlFree(obj as *mut c_void);
4050 return ptr::null_mut();
4051 }
4052 ptr::copy_nonoverlapping((*src_ns).nodeTab, tab, nr as usize);
4053 (*ns).nodeTab = tab;
4054 } else {
4055 (*ns).nodeTab = ptr::null_mut();
4056 }
4057 (*obj).nodesetval = ns as *mut c_void;
4058 }
4059 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
4060 (*obj).boolval = (*val).boolval;
4061 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
4062 (*obj).floatval = (*val).floatval;
4063 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
4064 let src = (*val).stringval;
4065 if !src.is_null() {
4066 let len = libc::strlen(src as *const libc::c_char);
4067 let buf = xmlMalloc(len + 1) as *mut xmlChar;
4068 if !buf.is_null() {
4069 ptr::copy_nonoverlapping(src, buf, len);
4070 *buf.add(len) = 0;
4071 }
4072 (*obj).stringval = buf;
4073 }
4074 }
4075 obj
4076}
4077
4078#[no_mangle]
4088pub unsafe extern "C" fn xmlXPathCastToString(val: *mut _xmlXPathObject) -> *mut xmlChar {
4089 if val.is_null() {
4090 return ptr::null_mut();
4091 }
4092 let typ = (*val).type_;
4093 let mut result: Vec<u8> = Vec::new();
4094 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
4095 if !(*val).stringval.is_null() {
4096 let len = libc::strlen((*val).stringval as *const libc::c_char);
4097 result.extend_from_slice(core::slice::from_raw_parts((*val).stringval, len));
4098 }
4099 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
4100 let n = (*val).floatval;
4106 result.extend_from_slice(xml_number_to_string(n).as_bytes());
4107 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
4108 result.extend_from_slice(if (*val).boolval != 0 {
4109 b"true"
4110 } else {
4111 b"false"
4112 });
4113 } else if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
4114 let ns = (*val).nodesetval as *mut _xmlNodeSet;
4117 if !ns.is_null() && (*ns).nodeNr > 0 && !(*ns).nodeTab.is_null() {
4118 let node = *(*ns).nodeTab;
4119 if !node.is_null() {
4120 let content = crate::xml::tree::node_get_content(node);
4121 if !content.is_null() {
4122 let len = libc::strlen(content as *const libc::c_char);
4123 result.extend_from_slice(core::slice::from_raw_parts(content, len));
4124 xmlFree(content as *mut c_void);
4125 }
4126 }
4127 }
4128 }
4129 let buf = xmlMalloc(result.len() + 1) as *mut xmlChar;
4131 if buf.is_null() {
4132 return ptr::null_mut();
4133 }
4134 if !result.is_empty() {
4135 ptr::copy_nonoverlapping(result.as_ptr(), buf, result.len());
4136 }
4137 *buf.add(result.len()) = 0;
4138 buf
4139}
4140
4141pub fn xml_number_to_string(n: f64) -> String {
4145 if n.is_nan() {
4146 return "NaN".to_string();
4147 }
4148 if n.is_infinite() {
4149 return if n > 0.0 {
4150 "Infinity".to_string()
4151 } else {
4152 "-Infinity".to_string()
4153 };
4154 }
4155 if n == 0.0 {
4156 return "0".to_string();
4158 }
4159 if n.fract() == 0.0 && n.abs() < 1e15 {
4161 return format!("{:.0}", n);
4162 }
4163 let mut s = format!("{:.15}", n);
4167 if s.contains('.') {
4169 while s.ends_with('0') {
4170 s.pop();
4171 }
4172 if s.ends_with('.') {
4173 s.pop();
4174 }
4175 }
4176 if s == "-0" {
4177 return "0".to_string();
4178 }
4179 s
4180}
4181
4182#[no_mangle]
4190pub unsafe extern "C" fn xmlXPathCastStringToNumber(val: *const xmlChar) -> f64 {
4191 if val.is_null() {
4192 return f64::NAN;
4193 }
4194 let len = libc::strlen(val as *const libc::c_char);
4195 let bytes = core::slice::from_raw_parts(val, len);
4196 let mut i = 0;
4198 while i < bytes.len() && matches!(bytes[i], b' ' | b'\t' | b'\n' | b'\r') {
4199 i += 1;
4200 }
4201 let s = &bytes[i..];
4202 if s.is_empty() {
4203 return f64::NAN;
4204 }
4205 let (sign, rest) = match s[0] {
4207 b'+' => (1.0f64, &s[1..]),
4208 b'-' => (-1.0f64, &s[1..]),
4209 _ => (1.0f64, s),
4210 };
4211 if rest.is_empty() {
4212 return f64::NAN;
4213 }
4214 let num_str = core::str::from_utf8(rest);
4217 match num_str {
4218 Ok(s) => {
4219 let valid = is_xpath_number(s);
4222 if !valid {
4223 f64::NAN
4224 } else {
4225 s.trim()
4226 .parse::<f64>()
4227 .map(|v| v * sign)
4228 .unwrap_or(f64::NAN)
4229 }
4230 }
4231 Err(_) => f64::NAN,
4232 }
4233}
4234
4235fn is_xpath_number(s: &str) -> bool {
4237 let b = s.as_bytes();
4238 if b.is_empty() {
4239 return false;
4240 }
4241 let mut i = 0;
4242 let mut saw_digit = false;
4243 while i < b.len() && b[i].is_ascii_digit() {
4244 saw_digit = true;
4245 i += 1;
4246 }
4247 if i < b.len() && b[i] == b'.' {
4248 i += 1;
4249 while i < b.len() && b[i].is_ascii_digit() {
4250 saw_digit = true;
4251 i += 1;
4252 }
4253 }
4254 if !saw_digit {
4255 return false;
4256 }
4257 if i < b.len() && (b[i] == b'e' || b[i] == b'E') {
4258 i += 1;
4259 if i < b.len() && (b[i] == b'+' || b[i] == b'-') {
4260 i += 1;
4261 }
4262 let mut saw_exp = false;
4263 while i < b.len() && b[i].is_ascii_digit() {
4264 saw_exp = true;
4265 i += 1;
4266 }
4267 if !saw_exp {
4268 return false;
4269 }
4270 }
4271 i == b.len()
4272}
4273
4274#[no_mangle]
4289pub unsafe extern "C" fn xmlXPathCmpNodes(node1: *mut _xmlNode, node2: *mut _xmlNode) -> c_int {
4290 if node1.is_null() || node2.is_null() {
4291 return 0;
4292 }
4293 if node1 == node2 {
4294 return 0;
4295 }
4296 let mut chain1: Vec<*mut _xmlNode> = Vec::new();
4298 let mut chain2: Vec<*mut _xmlNode> = Vec::new();
4299 let mut n = node1;
4300 while !n.is_null() {
4301 chain1.push(n);
4302 n = (*n).parent as *mut _xmlNode;
4303 }
4304 let mut n = node2;
4305 while !n.is_null() {
4306 chain2.push(n);
4307 n = (*n).parent as *mut _xmlNode;
4308 }
4309 let mut i = chain1.len();
4311 let mut j = chain2.len();
4312 while i > 0 && j > 0 && chain1[i - 1] == chain2[j - 1] {
4313 i -= 1;
4314 j -= 1;
4315 }
4316 if i == 0 && j == 0 {
4317 return 0; }
4319 if i == 0 {
4320 return -1; }
4322 if j == 0 {
4323 return 1; }
4325 let mut a = chain1[i - 1];
4327 let mut b = chain2[j - 1];
4328 while !a.is_null() && !b.is_null() {
4330 let pa = (*a).parent as *mut _xmlNode;
4331 let pb = (*b).parent as *mut _xmlNode;
4332 if pa == pb {
4333 break;
4334 }
4335 a = pa;
4336 b = pb;
4337 }
4338 let parent = (*a).parent as *mut _xmlNode;
4340 let mut child = if parent.is_null() {
4341 ptr::null_mut()
4342 } else {
4343 (*parent).children
4344 };
4345 while !child.is_null() {
4346 if child == a {
4347 return -1;
4348 }
4349 if child == b {
4350 return 1;
4351 }
4352 child = (*child).next;
4353 }
4354 0
4355}
4356
4357#[no_mangle]
4367pub unsafe extern "C" fn xmlXPathNodeSetCreate(val: *mut _xmlNode) -> *mut _xmlNodeSet {
4368 let ns = xmlMallocZero(size_of::<_xmlNodeSet>()) as *mut _xmlNodeSet;
4369 if ns.is_null() {
4370 return ptr::null_mut();
4371 }
4372 if val.is_null() {
4373 return ns;
4374 }
4375 let tab = xmlMalloc(core::mem::size_of::<*mut _xmlNode>()) as *mut *mut _xmlNode;
4376 if tab.is_null() {
4377 xmlFree(ns as *mut c_void);
4378 return ptr::null_mut();
4379 }
4380 *tab = val;
4381 (*ns).nodeTab = tab;
4382 (*ns).nodeNr = 1;
4383 (*ns).nodeMax = 1;
4384 ns
4385}
4386
4387#[no_mangle]
4399pub unsafe extern "C" fn xmlXPathFreeNodeSet(ns: *mut _xmlNodeSet) {
4400 if ns.is_null() {
4401 return;
4402 }
4403 if !(*ns).nodeTab.is_null() {
4404 xmlFree((*ns).nodeTab as *mut c_void);
4405 (*ns).nodeTab = ptr::null_mut();
4406 }
4407 (*ns).nodeNr = 0;
4408 (*ns).nodeMax = 0;
4409 xmlFree(ns as *mut c_void);
4410}
4411
4412#[no_mangle]
4423pub unsafe extern "C" fn xmlXPathCompile(str_: *const xmlChar) -> *mut c_void {
4424 if str_.is_null() {
4425 return ptr::null_mut();
4426 }
4427 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
4428 Ok(s) => s,
4429 Err(_) => return ptr::null_mut(),
4430 };
4431
4432 match crate::xml::xpath::compile(expr_str) {
4433 Some(compiled) => {
4434 let mut map = COMPILED_EXPRS.lock();
4435 let mut counter = NEXT_COMPILED_KEY.lock();
4436 let key = *counter;
4437 *counter += 1;
4438 map.insert(key, Box::new(compiled));
4439 key as *mut c_void
4440 }
4441 None => ptr::null_mut(),
4442 }
4443}
4444
4445#[no_mangle]
4453pub unsafe extern "C" fn xmlXPathFreeCompExpr(comp: *mut c_void) {
4454 if comp.is_null() {
4455 return;
4456 }
4457 let mut map = COMPILED_EXPRS.lock();
4458 map.remove(&(comp as u64));
4459}
4460
4461#[no_mangle]
4470pub unsafe extern "C" fn xmlXPathRegisterNs(
4471 ctxt: *mut _xmlXPathContext,
4472 prefix: *const xmlChar,
4473 ns_uri: *const xmlChar,
4474) -> c_int {
4475 if ctxt.is_null() || prefix.is_null() || ns_uri.is_null() {
4476 return -1;
4477 }
4478 let internal = (*ctxt).extra as *mut XPathContext;
4479 if internal.is_null() {
4480 return -1;
4481 }
4482 let internal = &mut *internal;
4483
4484 let prefix_str = match CStr::from_ptr(prefix as *const c_char).to_str() {
4485 Ok(s) => s,
4486 Err(_) => return -1,
4487 };
4488 let uri_str = match CStr::from_ptr(ns_uri as *const c_char).to_str() {
4489 Ok(s) => s,
4490 Err(_) => return -1,
4491 };
4492
4493 internal.register_namespace(prefix_str, uri_str);
4494 0
4495}
4496
4497#[no_mangle]
4511pub unsafe extern "C" fn xmlXPathRegisterFunc(
4512 ctxt: *mut _xmlXPathContext,
4513 name: *const xmlChar,
4514 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
4515) -> c_int {
4516 if ctxt.is_null() || name.is_null() {
4517 return -1;
4518 }
4519 let internal = (*ctxt).extra as *mut XPathContext;
4520 if internal.is_null() {
4521 return -1;
4522 }
4523 let internal = &mut *internal;
4524
4525 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4526 Ok(s) => s,
4527 Err(_) => return -1,
4528 };
4529
4530 if let Some(func) = f {
4531 let key = (SendSyncPtr((*ctxt).extra), name_str.to_string());
4533 C_FUNCTIONS.lock().insert(key, func);
4534 internal.register_function(name_str, c_func_stub);
4536 }
4537 0
4538}
4539
4540#[no_mangle]
4550pub unsafe extern "C" fn xmlXPathRegisterFuncNS(
4551 ctxt: *mut _xmlXPathContext,
4552 name: *const xmlChar,
4553 ns_uri: *const xmlChar,
4554 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
4555) -> c_int {
4556 if ctxt.is_null() || name.is_null() {
4557 return -1;
4558 }
4559 let internal = (*ctxt).extra as *mut XPathContext;
4560 if internal.is_null() {
4561 return -1;
4562 }
4563 let internal = &mut *internal;
4564
4565 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4566 Ok(s) => s,
4567 Err(_) => return -1,
4568 };
4569 let ns_str = if ns_uri.is_null() {
4570 String::new()
4571 } else {
4572 match CStr::from_ptr(ns_uri as *const c_char).to_str() {
4573 Ok(s) => s.to_string(),
4574 Err(_) => return -1,
4575 }
4576 };
4577
4578 let qualified = if ns_str.is_empty() {
4580 name_str.to_string()
4581 } else {
4582 format!("{{{}}}{}", ns_str, name_str)
4583 };
4584
4585 if let Some(func) = f {
4586 let key = (SendSyncPtr((*ctxt).extra), qualified.clone());
4587 C_FUNCTIONS.lock().insert(key, func);
4588 internal.register_function(&qualified, c_func_stub);
4589 }
4590 0
4591}
4592
4593#[no_mangle]
4602pub unsafe extern "C" fn xmlXPathRegisterVariable(
4603 ctxt: *mut _xmlXPathContext,
4604 name: *const xmlChar,
4605 value: *mut _xmlXPathObject,
4606) -> c_int {
4607 if ctxt.is_null() || name.is_null() || value.is_null() {
4608 return -1;
4609 }
4610 let internal = (*ctxt).extra as *mut XPathContext;
4611 if internal.is_null() {
4612 return -1;
4613 }
4614 let internal = &mut *internal;
4615
4616 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
4617 Ok(s) => s,
4618 Err(_) => return -1,
4619 };
4620
4621 let xpath_val = object_to_xpathvalue(value);
4622 internal.register_variable(name_str, xpath_val);
4623 0
4624}
4625
4626#[no_mangle]
4634pub unsafe extern "C" fn xmlXPathNewNodeSet(val: *mut _xmlNode) -> *mut _xmlXPathObject {
4635 let ns = if val.is_null() {
4636 NodeSet::new()
4637 } else {
4638 NodeSet::singleton(val)
4639 };
4640 xpath_to_object(XPathValue::NodeSet(ns))
4641}
4642
4643#[no_mangle]
4651pub unsafe extern "C" fn xmlXPathNewCString(val: *const xmlChar) -> *mut _xmlXPathObject {
4652 if val.is_null() {
4653 return xpath_to_object(XPathValue::String(String::new()));
4654 }
4655 let s = match CStr::from_ptr(val as *const c_char).to_str() {
4656 Ok(s) => s.to_string(),
4657 Err(_) => return ptr::null_mut(),
4658 };
4659 xpath_to_object(XPathValue::String(s))
4660}
4661
4662#[no_mangle]
4670pub extern "C" fn xmlXPathNewFloat(val: f64) -> *mut _xmlXPathObject {
4671 unsafe { xpath_to_object(XPathValue::Number(val)) }
4672}
4673
4674#[no_mangle]
4682pub extern "C" fn xmlXPathNewBoolean(val: c_int) -> *mut _xmlXPathObject {
4683 unsafe { xpath_to_object(XPathValue::Boolean(val != 0)) }
4684}
4685
4686#[no_mangle]
4700pub unsafe extern "C" fn xmlXPtrEval(expr: *const c_char, doc: *mut _xmlDoc) -> *mut _xmlNode {
4701 crate::xml::xpointer::xmlXPtrEval(expr, doc)
4702}
4703
4704#[no_mangle]
4716pub unsafe extern "C" fn xmlXIncludeProcess(doc: *mut _xmlDoc) -> c_int {
4717 crate::xml::xinclude::xinclude_process(doc)
4718}
4719
4720#[no_mangle]
4728pub unsafe extern "C" fn xmlXIncludeProcessFlags(doc: *mut _xmlDoc, flags: c_int) -> c_int {
4729 crate::xml::xinclude::xinclude_process_flags(doc, flags)
4730}
4731
4732#[no_mangle]
4744pub extern "C" fn xmlCatalogLoad(catalogs: *const c_char) -> *mut c_void {
4745 if catalogs.is_null() {
4746 return ptr::null_mut();
4747 }
4748 crate::xml::catalog::load_catalog(catalogs)
4749}
4750
4751#[no_mangle]
4759pub unsafe extern "C" fn xmlCatalogResolvePublic(pubID: *const xmlChar) -> *mut xmlChar {
4760 if pubID.is_null() {
4761 return ptr::null_mut();
4762 }
4763 crate::xml::catalog::resolve_public(pubID)
4764}
4765
4766#[no_mangle]
4774pub unsafe extern "C" fn xmlCatalogResolveSystem(sysID: *const xmlChar) -> *mut xmlChar {
4775 if sysID.is_null() {
4776 return ptr::null_mut();
4777 }
4778 crate::xml::catalog::resolve_system(sysID)
4779}
4780
4781#[no_mangle]
4789pub unsafe extern "C" fn xmlCatalogResolveURI(URI: *const xmlChar) -> *mut xmlChar {
4790 if URI.is_null() {
4791 return ptr::null_mut();
4792 }
4793 crate::xml::catalog::resolve_uri(URI)
4794}
4795
4796#[no_mangle]
4804pub extern "C" fn xmlCatalogSetDefaults(allow: c_int) {
4805 crate::xml::catalog::set_defaults(allow)
4806}
4807
4808#[no_mangle]
4816pub extern "C" fn xmlCatalogGetDefaults() -> c_int {
4817 crate::xml::catalog::get_defaults()
4818}
4819
4820#[no_mangle]
4828pub unsafe extern "C" fn xmlCatalogAdd(
4829 type_: *const xmlChar,
4830 orig: *const xmlChar,
4831 replace: *const xmlChar,
4832) -> c_int {
4833 if type_.is_null() || orig.is_null() || replace.is_null() {
4834 return -1;
4835 }
4836 crate::xml::catalog::add(type_, orig, replace)
4837}
4838
4839#[no_mangle]
4847pub unsafe extern "C" fn xmlCatalogRemove(value: *const xmlChar) -> c_int {
4848 if value.is_null() {
4849 return 0;
4850 }
4851 crate::xml::catalog::remove(value)
4852}
4853
4854#[no_mangle]
4862pub unsafe extern "C" fn xmlCatalogDump(output: *mut c_void, _catal: *mut c_void) {
4863 if output.is_null() {
4864 return;
4865 }
4866 let doc = crate::xml::catalog::dump_doc();
4867 if doc.is_null() {
4868 return;
4869 }
4870 let mut mem: *mut xmlChar = ptr::null_mut();
4871 let mut size: c_int = 0;
4872 crate::xml::tree::xmlDocDumpFormatMemory(doc, &mut mem, &mut size, 1);
4873 if !mem.is_null() {
4874 libc::fwrite(
4875 mem as *const c_void,
4876 1,
4877 size as usize,
4878 output as *mut libc::FILE,
4879 );
4880 xmlFree(mem as *mut c_void);
4881 }
4882 crate::xml::tree::free_doc(doc);
4883}
4884
4885#[no_mangle]
4895pub unsafe extern "C" fn xmlCatalogSave(filename: *const c_char) -> c_int {
4896 if filename.is_null() {
4897 return -1;
4898 }
4899 let doc = crate::xml::catalog::dump_doc();
4900 if doc.is_null() {
4901 return -1;
4902 }
4903 let mut mem: *mut xmlChar = ptr::null_mut();
4904 let mut size: c_int = 0;
4905 crate::xml::tree::xmlDocDumpFormatMemory(doc, &mut mem, &mut size, 1);
4906 let mut ret: c_int = -1;
4907 if !mem.is_null() {
4908 let fp = libc::fopen(filename, b"w\0".as_ptr() as *const c_char);
4909 if !fp.is_null() {
4910 let written = libc::fwrite(mem as *const c_void, 1, size as usize, fp);
4911 ret = if written == size as usize { 0 } else { -1 };
4912 libc::fclose(fp);
4913 }
4914 xmlFree(mem as *mut c_void);
4915 }
4916 crate::xml::tree::free_doc(doc);
4917 ret
4918}
4919
4920#[no_mangle]
4928pub extern "C" fn xmlCatalogCleanup() {
4929 crate::xml::catalog::cleanup();
4930}
4931
4932#[no_mangle]
4940pub extern "C" fn xmlCatalogConvert() -> *mut _xmlDoc {
4941 unsafe { crate::xml::catalog::convert() }
4943}
4944
4945#[no_mangle]
4957pub unsafe extern "C" fn htmlParseFile(
4958 _filename: *const c_char,
4959 _encoding: *const c_char,
4960) -> *mut _xmlDoc {
4961 ptr::null_mut()
4963}
4964
4965#[no_mangle]
4973pub unsafe extern "C" fn htmlParseMemory(_buffer: *const c_char, _size: c_int) -> *mut _xmlDoc {
4974 ptr::null_mut()
4976}
4977
4978#[no_mangle]
4986pub unsafe extern "C" fn htmlParseDoc(
4987 _cur: *const xmlChar,
4988 _encoding: *const c_char,
4989) -> *mut _xmlDoc {
4990 ptr::null_mut()
4992}
4993
4994#[no_mangle]
5003pub unsafe extern "C" fn htmlCreateFileParserCtxt(
5004 _filename: *const c_char,
5005 _encoding: *const c_char,
5006) -> *mut c_void {
5007 ptr::null_mut()
5009}
5010
5011#[no_mangle]
5019pub extern "C" fn htmlFreeParserCtxt(_ctxt: *mut c_void) {
5020 }
5022
5023#[no_mangle]
5031pub extern "C" fn htmlInitParser() {
5032 }
5034
5035#[no_mangle]
5043pub extern "C" fn htmlCleanupParser() {
5044 }
5046
5047#[no_mangle]
5059pub unsafe extern "C" fn xmlNewValidCtxt() -> *mut _xmlValidCtxt {
5060 crate::xml::validation::new_valid_ctxt()
5061}
5062
5063#[no_mangle]
5071pub unsafe extern "C" fn xmlFreeValidCtxt(ctxt: *mut _xmlValidCtxt) {
5072 crate::xml::validation::free_valid_ctxt(ctxt);
5073}
5074
5075#[no_mangle]
5086pub unsafe extern "C" fn xmlSetValidErrors(
5087 ctxt: *mut _xmlValidCtxt,
5088 err: Option<xmlGenericErrorFunc>,
5089 warn: Option<xmlGenericErrorFunc>,
5090 data: *mut c_void,
5091) {
5092 crate::xml::validation::set_valid_errors(ctxt, err, warn, data);
5093}
5094
5095#[no_mangle]
5103pub unsafe extern "C" fn xmlValidateDocument(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5104 crate::xml::validation::validate_document(ctxt, doc)
5105}
5106
5107#[no_mangle]
5115pub unsafe extern "C" fn xmlValidateDocumentFinal(
5116 ctxt: *mut _xmlValidCtxt,
5117 doc: *mut _xmlDoc,
5118) -> c_int {
5119 crate::xml::validation::validate_document_final(ctxt, doc)
5120}
5121
5122#[no_mangle]
5132pub unsafe extern "C" fn xmlValidateElement(
5133 ctxt: *mut _xmlValidCtxt,
5134 doc: *mut _xmlDoc,
5135 elem: *mut _xmlNode,
5136) -> c_int {
5137 crate::xml::validation::validate_element(ctxt, doc, elem)
5138}
5139
5140#[no_mangle]
5151pub unsafe extern "C" fn xmlValidateAttributeDecl(
5152 ctxt: *mut _xmlValidCtxt,
5153 doc: *mut _xmlDoc,
5154 elem: *mut _xmlNode,
5155 attr: *mut _xmlAttribute,
5156) -> c_int {
5157 crate::xml::validation::validate_attribute_decl(ctxt, doc, elem, attr)
5158}
5159
5160#[no_mangle]
5168pub unsafe extern "C" fn xmlValidateAttributeValue(atype: c_int, value: *const xmlChar) -> c_int {
5169 crate::xml::validation::validate_attribute_value(atype, value)
5170}
5171
5172#[no_mangle]
5182pub unsafe extern "C" fn xmlValidateNotationUse(
5183 ctxt: *mut _xmlValidCtxt,
5184 doc: *mut _xmlDoc,
5185 notation_name: *const xmlChar,
5186) -> c_int {
5187 crate::xml::validation::validate_notation_use(ctxt, doc, notation_name)
5188}
5189
5190#[no_mangle]
5201pub unsafe extern "C" fn xmlValidateID(
5202 ctxt: *mut _xmlValidCtxt,
5203 doc: *mut _xmlDoc,
5204 node: *mut _xmlNode,
5205 value: *const xmlChar,
5206) -> c_int {
5207 crate::xml::validation::validate_id(ctxt, doc, node, value)
5208}
5209
5210#[no_mangle]
5221pub unsafe extern "C" fn xmlValidateIDRef(
5222 ctxt: *mut _xmlValidCtxt,
5223 doc: *mut _xmlDoc,
5224 node: *mut _xmlNode,
5225 value: *const xmlChar,
5226) -> c_int {
5227 crate::xml::validation::validate_id_ref(ctxt, doc, node, value)
5228}
5229
5230#[no_mangle]
5241pub unsafe extern "C" fn xmlValidateIDRefs(
5242 ctxt: *mut _xmlValidCtxt,
5243 doc: *mut _xmlDoc,
5244 node: *mut _xmlNode,
5245 value: *const xmlChar,
5246) -> c_int {
5247 crate::xml::validation::validate_id_refs(ctxt, doc, node, value)
5248}
5249
5250#[no_mangle]
5258pub unsafe extern "C" fn xmlValidateNmtoken(value: *const xmlChar) -> c_int {
5259 crate::xml::validation::validate_nmtoken(value)
5260}
5261
5262#[no_mangle]
5270pub unsafe extern "C" fn xmlValidateNmtokens(value: *const xmlChar) -> c_int {
5271 crate::xml::validation::validate_nmtokens(value)
5272}
5273
5274#[no_mangle]
5282pub unsafe extern "C" fn xmlValidateName(value: *const xmlChar) -> c_int {
5283 crate::xml::validation::validate_name(value)
5284}
5285
5286#[no_mangle]
5294pub unsafe extern "C" fn xmlValidateNames(value: *const xmlChar) -> c_int {
5295 crate::xml::validation::validate_names(value)
5296}
5297
5298#[no_mangle]
5306pub unsafe extern "C" fn xmlValidateRoot(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5307 crate::xml::validation::validate_root(ctxt, doc)
5308}
5309
5310#[no_mangle]
5320pub unsafe extern "C" fn xmlValidateContent(
5321 ctxt: *mut _xmlValidCtxt,
5322 node: *mut _xmlNode,
5323 doc: *mut _xmlDoc,
5324) -> c_int {
5325 crate::xml::validation::validate_content(ctxt, node, doc)
5326}
5327
5328#[no_mangle]
5336pub unsafe extern "C" fn xmlIsMixedElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
5337 crate::xml::validation::is_mixed_element(doc, name)
5338}
5339
5340#[no_mangle]
5348pub unsafe extern "C" fn xmlIsEmptyElement(doc: *mut _xmlDoc, name: *const xmlChar) -> c_int {
5349 crate::xml::validation::is_empty_element(doc, name)
5350}
5351
5352#[no_mangle]
5362pub unsafe extern "C" fn xmlValidateDtd(
5363 ctxt: *mut _xmlValidCtxt,
5364 doc: *mut _xmlDoc,
5365 dtd: *mut _xmlDtd,
5366) -> c_int {
5367 crate::xml::validation::validate_dtd(ctxt, doc, dtd)
5368}
5369
5370#[no_mangle]
5378pub unsafe extern "C" fn xmlValidateDtdFinal(ctxt: *mut _xmlValidCtxt, doc: *mut _xmlDoc) -> c_int {
5379 crate::xml::validation::validate_dtd_final(ctxt, doc)
5380}
5381
5382#[no_mangle]
5392pub unsafe extern "C" fn xmlValidateEnumeration(
5393 ctxt: *mut _xmlValidCtxt,
5394 value: *const xmlChar,
5395 tree: *mut _xmlEnumeration,
5396) -> c_int {
5397 crate::xml::validation::validate_enumeration(ctxt, value, tree)
5398}
5399
5400#[no_mangle]
5414pub extern "C" fn xmlGetBinaryPath() -> *mut c_char {
5415 ptr::null_mut()
5417}
5418
5419#[no_mangle]
5427pub extern "C" fn xmlGetHomeOfBinary() -> *mut c_char {
5428 ptr::null_mut()
5430}