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]
1269pub extern "C" fn xmlGetLineNo(node: *const _xmlNode) -> c_int {
1270 crate::xml::tree::get_line_no(node)
1271}
1272
1273#[no_mangle]
1285pub unsafe extern "C" fn xmlNodeDump(
1286 buf: *mut _xmlBuffer,
1287 doc: *mut _xmlDoc,
1288 cur: *mut _xmlNode,
1289 level: c_int,
1290 format: c_int,
1291) -> c_int {
1292 if buf.is_null() || cur.is_null() {
1293 return -1;
1294 }
1295 crate::xml::tree::xmlNodeDump(buf, doc, cur, level, format)
1296}
1297
1298#[no_mangle]
1306pub unsafe extern "C" fn xmlDocDump(fp: *mut c_void, doc: *mut _xmlDoc) -> c_int {
1307 if fp.is_null() || doc.is_null() {
1308 return -1;
1309 }
1310 crate::xml::tree::xmlDocDump(fp, doc)
1311}
1312
1313#[no_mangle]
1321pub unsafe extern "C" fn xmlDocDumpFormatMemory(
1322 doc: *mut _xmlDoc,
1323 mem: *mut *mut xmlChar,
1324 size: *mut c_int,
1325 format: c_int,
1326) {
1327 if doc.is_null() || mem.is_null() || size.is_null() {
1328 return;
1329 }
1330 crate::xml::tree::xmlDocDumpFormatMemory(doc, mem, size, format)
1331}
1332
1333#[no_mangle]
1341pub unsafe extern "C" fn xmlDocDumpMemory(
1342 doc: *mut _xmlDoc,
1343 mem: *mut *mut xmlChar,
1344 size: *mut c_int,
1345) {
1346 if doc.is_null() || mem.is_null() || size.is_null() {
1347 return;
1348 }
1349 crate::xml::tree::xmlDocDumpMemory(doc, mem, size)
1350}
1351
1352#[no_mangle]
1360pub unsafe extern "C" fn xmlSaveFile(filename: *const c_char, cur: *mut _xmlDoc) -> c_int {
1361 if filename.is_null() || cur.is_null() {
1362 return -1;
1363 }
1364 crate::xml::tree::xmlSaveFile(filename, cur)
1365}
1366
1367#[no_mangle]
1375pub unsafe extern "C" fn xmlSaveFileEnc(
1376 filename: *const c_char,
1377 cur: *mut _xmlDoc,
1378 encoding: *const c_char,
1379) -> c_int {
1380 if filename.is_null() || cur.is_null() {
1381 return -1;
1382 }
1383 crate::xml::tree::xmlSaveFileEnc(filename, cur, encoding)
1384}
1385
1386#[no_mangle]
1394pub unsafe extern "C" fn xmlSaveFormatFile(
1395 filename: *const c_char,
1396 cur: *mut _xmlDoc,
1397 format: c_int,
1398) -> c_int {
1399 if filename.is_null() || cur.is_null() {
1400 return -1;
1401 }
1402 crate::xml::tree::xmlSaveFormatFile(filename, cur, format)
1403}
1404
1405#[no_mangle]
1413pub unsafe extern "C" fn xmlSaveFormatFileEnc(
1414 filename: *const c_char,
1415 cur: *mut _xmlDoc,
1416 encoding: *const c_char,
1417 format: c_int,
1418) -> c_int {
1419 if filename.is_null() || cur.is_null() {
1420 return -1;
1421 }
1422 crate::xml::tree::xmlSaveFormatFileEnc(filename, cur, encoding, format)
1423}
1424
1425#[no_mangle]
1440pub unsafe extern "C" fn xmlReadDoc(
1441 cur: *const xmlChar,
1442 URL: *const c_char,
1443 encoding: *const c_char,
1444 options: c_int,
1445) -> *mut _xmlDoc {
1446 if cur.is_null() {
1448 return ptr::null_mut();
1449 }
1450 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1451 if ctxt.is_null() {
1452 return ptr::null_mut();
1453 }
1454 let len = crate::xml::string::xml_strlen(cur);
1455 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
1456 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1457 (*ctxt).options = options;
1458 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1459 let doc = (*ctxt).myDoc;
1460 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1461 return doc;
1462 }
1463 let doc = (*ctxt).myDoc;
1464 if !doc.is_null() {
1465 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1466 }
1467 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1468 doc
1469}
1470
1471#[no_mangle]
1479pub unsafe extern "C" fn xmlReadFile(
1480 URL: *const c_char,
1481 encoding: *const c_char,
1482 options: c_int,
1483) -> *mut _xmlDoc {
1484 if URL.is_null() {
1486 return ptr::null_mut();
1487 }
1488 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1489 if ctxt.is_null() {
1490 return ptr::null_mut();
1491 }
1492 let input = match crate::xml::parser::helpers::input_from_file(URL) {
1493 Ok(input) => input,
1494 Err(_) => {
1495 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1496 return ptr::null_mut();
1497 }
1498 };
1499 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1500 (*ctxt).options = options;
1501 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1502 let doc = (*ctxt).myDoc;
1503 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1504 return doc;
1505 }
1506 let doc = (*ctxt).myDoc;
1507 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1508 doc
1509}
1510
1511#[no_mangle]
1520pub unsafe extern "C" fn xmlReadMemory(
1521 buffer: *const c_char,
1522 size: c_int,
1523 URL: *const c_char,
1524 encoding: *const c_char,
1525 options: c_int,
1526) -> *mut _xmlDoc {
1527 if buffer.is_null() || size <= 0 {
1529 return ptr::null_mut();
1530 }
1531 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1532 if ctxt.is_null() {
1533 return ptr::null_mut();
1534 }
1535 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
1536 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1537 (*ctxt).options = options;
1538 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1539 let doc = (*ctxt).myDoc;
1540 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1541 return doc;
1542 }
1543 let doc = (*ctxt).myDoc;
1544 if !doc.is_null() && !URL.is_null() {
1545 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1546 }
1547 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1548 doc
1549}
1550
1551#[no_mangle]
1559pub unsafe extern "C" fn xmlReadFd(
1560 fd: c_int,
1561 URL: *const c_char,
1562 encoding: *const c_char,
1563 options: c_int,
1564) -> *mut _xmlDoc {
1565 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1567 if ctxt.is_null() {
1568 return ptr::null_mut();
1569 }
1570 let mut buf = Vec::new();
1572 let mut tmp = [0u8; 4096];
1573 loop {
1574 let n = libc::read(fd, tmp.as_mut_ptr() as *mut c_void, tmp.len());
1575 if n <= 0 {
1576 break;
1577 }
1578 buf.extend_from_slice(&tmp[..n as usize]);
1579 }
1580 let input = crate::xml::parser::helpers::input_from_memory(
1581 buf.as_ptr() as *const c_char,
1582 buf.len() as c_int,
1583 );
1584 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1585 (*ctxt).options = options;
1586 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1587 let doc = (*ctxt).myDoc;
1588 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1589 return doc;
1590 }
1591 let doc = (*ctxt).myDoc;
1592 if !doc.is_null() && !URL.is_null() {
1593 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1594 }
1595 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1596 doc
1597}
1598
1599#[no_mangle]
1608pub unsafe extern "C" fn xmlReadIO(
1609 ioread: Option<xmlInputReadCallback>,
1610 ioclose: Option<xmlInputCloseCallback>,
1611 ioctx: *mut c_void,
1612 URL: *const c_char,
1613 encoding: *const c_char,
1614 options: c_int,
1615) -> *mut _xmlDoc {
1616 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1618 if ctxt.is_null() {
1619 return ptr::null_mut();
1620 }
1621 let input = crate::xml::parser::helpers::input_from_io(ioread, ioclose, ioctx);
1622 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1623 (*ctxt).options = options;
1624 if crate::xml::parser::helpers::parse_document(ctxt) != 0 {
1625 let doc = (*ctxt).myDoc;
1626 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1627 return doc;
1628 }
1629 let doc = (*ctxt).myDoc;
1630 if !doc.is_null() && !URL.is_null() {
1631 (*doc).URL = crate::xml::string::xml_strdup(URL as *const xmlChar);
1632 }
1633 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1634 doc
1635}
1636
1637#[no_mangle]
1645pub unsafe extern "C" fn xmlSAXParseDoc(
1646 sax: *mut _xmlSAXHandler,
1647 cur: *const xmlChar,
1648 recovery: c_int,
1649) -> *mut _xmlDoc {
1650 if cur.is_null() {
1652 return ptr::null_mut();
1653 }
1654 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1655 if ctxt.is_null() {
1656 return ptr::null_mut();
1657 }
1658 if !sax.is_null() {
1659 (*ctxt).sax = sax;
1660 (*ctxt).userData = (*ctxt).sax as *mut c_void;
1661 }
1662 if recovery != 0 {
1663 (*ctxt).recovery = 1;
1664 (*ctxt).options |= 1; }
1666 let len = crate::xml::string::xml_strlen(cur);
1667 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
1668 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1669 crate::xml::parser::helpers::parse_document(ctxt);
1670 let doc = (*ctxt).myDoc;
1671 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1672 doc
1673}
1674
1675#[no_mangle]
1683pub unsafe extern "C" fn xmlSAXParseFile(
1684 sax: *mut _xmlSAXHandler,
1685 filename: *const c_char,
1686 recovery: c_int,
1687) -> *mut _xmlDoc {
1688 if filename.is_null() {
1690 return ptr::null_mut();
1691 }
1692 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1693 if ctxt.is_null() {
1694 return ptr::null_mut();
1695 }
1696 if !sax.is_null() {
1697 (*ctxt).sax = sax;
1698 (*ctxt).userData = (*ctxt).sax as *mut c_void;
1699 }
1700 if recovery != 0 {
1701 (*ctxt).recovery = 1;
1702 (*ctxt).options |= 1;
1703 }
1704 let input = match crate::xml::parser::helpers::input_from_file(filename) {
1705 Ok(input) => input,
1706 Err(_) => {
1707 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1708 return ptr::null_mut();
1709 }
1710 };
1711 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1712 crate::xml::parser::helpers::parse_document(ctxt);
1713 let doc = (*ctxt).myDoc;
1714 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1715 doc
1716}
1717
1718#[no_mangle]
1727pub unsafe extern "C" fn xmlSAXParseMemory(
1728 sax: *mut _xmlSAXHandler,
1729 buffer: *const c_char,
1730 size: c_int,
1731 recovery: c_int,
1732) -> *mut _xmlDoc {
1733 if buffer.is_null() || size <= 0 {
1735 return ptr::null_mut();
1736 }
1737 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1738 if ctxt.is_null() {
1739 return ptr::null_mut();
1740 }
1741 if !sax.is_null() {
1742 (*ctxt).sax = sax;
1743 (*ctxt).userData = (*ctxt).sax as *mut c_void;
1744 }
1745 if recovery != 0 {
1746 (*ctxt).recovery = 1;
1747 (*ctxt).options |= 1;
1748 }
1749 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
1750 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1751 crate::xml::parser::helpers::parse_document(ctxt);
1752 let doc = (*ctxt).myDoc;
1753 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1754 doc
1755}
1756
1757#[no_mangle]
1766pub unsafe extern "C" fn xmlSAXUserParseFile(
1767 sax: *mut _xmlSAXHandler,
1768 user_data: *mut c_void,
1769 filename: *const c_char,
1770) -> c_int {
1771 if filename.is_null() {
1773 return -1;
1774 }
1775 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1776 if ctxt.is_null() {
1777 return -1;
1778 }
1779 if !sax.is_null() {
1780 (*ctxt).sax = sax;
1781 }
1782 (*ctxt).userData = if !user_data.is_null() {
1783 user_data
1784 } else {
1785 ctxt as *mut c_void
1786 };
1787 let input = match crate::xml::parser::helpers::input_from_file(filename) {
1788 Ok(input) => input,
1789 Err(_) => {
1790 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1791 return -1;
1792 }
1793 };
1794 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1795 let ret = crate::xml::parser::helpers::parse_document(ctxt);
1796 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1797 ret
1798}
1799
1800#[no_mangle]
1809pub unsafe extern "C" fn xmlSAXUserParseMemory(
1810 sax: *mut _xmlSAXHandler,
1811 user_data: *mut c_void,
1812 buffer: *const c_char,
1813 size: c_int,
1814) -> c_int {
1815 if buffer.is_null() || size <= 0 {
1817 return -1;
1818 }
1819 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1820 if ctxt.is_null() {
1821 return -1;
1822 }
1823 if !sax.is_null() {
1824 (*ctxt).sax = sax;
1825 }
1826 (*ctxt).userData = if !user_data.is_null() {
1827 user_data
1828 } else {
1829 ctxt as *mut c_void
1830 };
1831 let input = crate::xml::parser::helpers::input_from_memory(buffer, size);
1832 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1833 let ret = crate::xml::parser::helpers::parse_document(ctxt);
1834 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1835 ret
1836}
1837
1838#[no_mangle]
1846pub unsafe extern "C" fn xmlParseDoc(cur: *const xmlChar) -> *mut _xmlDoc {
1847 if cur.is_null() {
1849 return ptr::null_mut();
1850 }
1851 xmlReadDoc(cur, ptr::null(), ptr::null(), 0)
1852}
1853
1854#[no_mangle]
1862pub unsafe extern "C" fn xmlParseFile(filename: *const c_char) -> *mut _xmlDoc {
1863 if filename.is_null() {
1865 return ptr::null_mut();
1866 }
1867 xmlReadFile(filename, ptr::null(), 0)
1868}
1869
1870#[no_mangle]
1878pub unsafe extern "C" fn xmlParseMemory(buffer: *const c_char, size: c_int) -> *mut _xmlDoc {
1879 if buffer.is_null() || size <= 0 {
1881 return ptr::null_mut();
1882 }
1883 xmlReadMemory(buffer, size, ptr::null(), ptr::null(), 0)
1884}
1885
1886#[no_mangle]
1894pub unsafe extern "C" fn xmlCreateFileParserCtxt(filename: *const c_char) -> *mut _xmlParserCtxt {
1895 if filename.is_null() {
1897 return ptr::null_mut();
1898 }
1899 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1900 if ctxt.is_null() {
1901 return ptr::null_mut();
1902 }
1903 let input = match crate::xml::parser::helpers::input_from_file(filename) {
1904 Ok(input) => input,
1905 Err(_) => {
1906 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1907 return ptr::null_mut();
1908 }
1909 };
1910 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1911 ctxt
1912}
1913
1914#[no_mangle]
1922pub unsafe extern "C" fn xmlCreateDocParserCtxt(cur: *const xmlChar) -> *mut _xmlParserCtxt {
1923 if cur.is_null() {
1925 return ptr::null_mut();
1926 }
1927 let ctxt = crate::xml::parser::helpers::create_parser_ctxt();
1928 if ctxt.is_null() {
1929 return ptr::null_mut();
1930 }
1931 let len = crate::xml::string::xml_strlen(cur);
1932 let input = crate::xml::parser::helpers::input_from_memory(cur as *const c_char, len as c_int);
1933 crate::xml::parser::helpers::setup_parser_input(ctxt, input);
1934 ctxt
1935}
1936
1937#[no_mangle]
1945pub unsafe extern "C" fn xmlParseDocument(ctxt: *mut _xmlParserCtxt) -> c_int {
1946 if ctxt.is_null() {
1948 return -1;
1949 }
1950 crate::xml::parser::helpers::parse_document(ctxt)
1951}
1952
1953#[no_mangle]
1961pub unsafe extern "C" fn xmlFreeParserCtxt(ctxt: *mut _xmlParserCtxt) {
1962 if ctxt.is_null() {
1963 return;
1964 }
1965 crate::xml::parser::helpers::free_parser_ctxt(ctxt);
1966}
1967
1968#[no_mangle]
1976pub unsafe extern "C" fn xmlCtxtUseOptions(ctxt: *mut _xmlParserCtxt, options: c_int) -> c_int {
1977 if ctxt.is_null() {
1978 return -1;
1979 }
1980 unsafe {
1982 (*ctxt).options = options;
1983 }
1984 0
1985}
1986
1987#[no_mangle]
1996pub unsafe extern "C" fn xmlParseChunk(
1997 ctxt: *mut _xmlParserCtxt,
1998 chunk: *const c_char,
1999 size: c_int,
2000 terminate: c_int,
2001) -> c_int {
2002 if ctxt.is_null() {
2005 return -1;
2006 }
2007 crate::xml::parser::helpers::parse_chunk(ctxt, chunk, size, terminate)
2008}
2009
2010#[no_mangle]
2018pub unsafe extern "C" fn xmlParserInputBufferCreateMem(
2019 buffer: *const c_char,
2020 size: c_int,
2021 enc: c_int,
2022) -> *mut _xmlParserInputBuffer {
2023 if buffer.is_null() || size <= 0 {
2025 return ptr::null_mut();
2026 }
2027 crate::xml::parser::helpers::alloc_parser_input_buffer()
2028}
2029
2030#[no_mangle]
2038pub unsafe extern "C" fn xmlParserInputBufferCreateFilename(
2039 URI: *const c_char,
2040 enc: c_int,
2041) -> *mut _xmlParserInputBuffer {
2042 if URI.is_null() {
2044 return ptr::null_mut();
2045 }
2046 crate::xml::parser::helpers::alloc_parser_input_buffer()
2047}
2048
2049#[no_mangle]
2059pub unsafe extern "C" fn xmlParserInputBufferCreateIO(
2060 ioread: Option<xmlInputReadCallback>,
2061 ioclose: Option<xmlInputCloseCallback>,
2062 ioctx: *mut c_void,
2063 enc: c_int,
2064) -> *mut _xmlParserInputBuffer {
2065 let buf = crate::xml::parser::helpers::alloc_parser_input_buffer();
2067 if !buf.is_null() {
2068 (*buf).readcallback = ioread;
2069 (*buf).closecallback = ioclose;
2070 (*buf).context = ioctx;
2071 }
2072 buf
2073}
2074
2075#[no_mangle]
2083pub unsafe extern "C" fn xmlFreeParserInputBuffer(buf: *mut _xmlParserInputBuffer) {
2084 if buf.is_null() {
2085 return;
2086 }
2087 crate::xml::parser::helpers::free_parser_input_buffer(buf);
2088}
2089
2090#[no_mangle]
2098pub unsafe extern "C" fn xmlNewInputFromFile(
2099 ctxt: *mut _xmlParserCtxt,
2100 filename: *const c_char,
2101) -> *mut _xmlParserInput {
2102 if filename.is_null() {
2107 return ptr::null_mut();
2108 }
2109 crate::xml::parser::helpers::alloc_parser_input_buffer() as *mut _xmlParserInput
2110}
2111
2112#[no_mangle]
2120pub unsafe extern "C" fn xmlFreeInputStream(input: *mut _xmlParserInput) {
2121 if input.is_null() {
2122 return;
2123 }
2124 crate::xml::parser::helpers::free_parser_input(input);
2125}
2126
2127#[no_mangle]
2141pub unsafe extern "C" fn xmlOutputBufferCreateFilename(
2142 URI: *const c_char,
2143 encoder: *mut c_void,
2144 compression: c_int,
2145) -> *mut _xmlOutputBuffer {
2146 let _ = compression;
2147 if URI.is_null() {
2148 return ptr::null_mut();
2149 }
2150 crate::xml::io::output_buffer_create_filename(
2151 URI,
2152 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2153 0,
2154 )
2155}
2156
2157#[no_mangle]
2166pub unsafe extern "C" fn xmlOutputBufferCreateFd(
2167 fd: c_int,
2168 encoder: *mut c_void,
2169) -> *mut _xmlOutputBuffer {
2170 if fd < 0 {
2171 return ptr::null_mut();
2172 }
2173 crate::xml::io::output_buffer_create_fd(
2174 fd,
2175 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2176 )
2177}
2178
2179#[no_mangle]
2189pub unsafe extern "C" fn xmlOutputBufferCreateIO(
2190 iowrite: Option<xmlOutputWriteCallback>,
2191 ioclose: Option<xmlOutputCloseCallback>,
2192 ioctx: *mut c_void,
2193 encoder: *mut c_void,
2194) -> *mut _xmlOutputBuffer {
2195 crate::xml::io::output_buffer_create_io(
2196 iowrite,
2197 ioclose,
2198 ioctx,
2199 encoder as *mut crate::abi::structs::_xmlCharEncodingHandler,
2200 )
2201}
2202
2203#[no_mangle]
2211pub unsafe extern "C" fn xmlOutputBufferClose(out: *mut _xmlOutputBuffer) -> c_int {
2212 if out.is_null() {
2213 return -1;
2214 }
2215 crate::xml::io::output_buffer_close(out)
2216}
2217
2218#[no_mangle]
2226pub unsafe extern "C" fn xmlOutputBufferFlush(out: *mut _xmlOutputBuffer) -> c_int {
2227 if out.is_null() {
2228 return -1;
2229 }
2230 crate::xml::io::output_buffer_flush(out)
2231}
2232
2233#[no_mangle]
2241pub unsafe extern "C" fn xmlOutputBufferWrite(
2242 out: *mut _xmlOutputBuffer,
2243 len: c_int,
2244 data: *const c_char,
2245) -> c_int {
2246 if out.is_null() || data.is_null() || len <= 0 {
2247 return -1;
2248 }
2249 crate::xml::io::output_buffer_write(out, len, data)
2250}
2251
2252#[no_mangle]
2260pub unsafe extern "C" fn xmlOutputBufferWriteString(
2261 out: *mut _xmlOutputBuffer,
2262 str: *const c_char,
2263) -> c_int {
2264 if str.is_null() {
2265 return 0;
2266 }
2267 unsafe { xmlOutputBufferWrite(out, xmlStrlen(str as *const xmlChar), str) }
2268}
2269
2270#[no_mangle]
2282pub extern "C" fn xmlDictCreate() -> *mut c_void {
2283 ptr::null_mut()
2285}
2286
2287#[no_mangle]
2295pub extern "C" fn xmlDictCreateSub(_sub: *mut c_void) -> *mut c_void {
2296 ptr::null_mut()
2298}
2299
2300#[no_mangle]
2312pub unsafe extern "C" fn xmlDictLookup(
2313 dict: *mut c_void,
2314 name: *const xmlChar,
2315 len: c_int,
2316) -> *const xmlChar {
2317 name
2319}
2320
2321#[no_mangle]
2329pub unsafe extern "C" fn xmlDictExists(
2330 dict: *mut c_void,
2331 name: *const xmlChar,
2332 len: c_int,
2333) -> *const xmlChar {
2334 ptr::null()
2336}
2337
2338#[no_mangle]
2346pub extern "C" fn xmlDictSize(dict: *const c_void) -> c_uint {
2347 0
2349}
2350
2351#[no_mangle]
2359pub extern "C" fn xmlDictFree(_dict: *mut c_void) {
2360 }
2362
2363#[no_mangle]
2371pub extern "C" fn xmlDictSetLimit(_dict: *mut c_void, _limit: c_uint) -> c_uint {
2372 0
2374}
2375
2376#[no_mangle]
2384pub extern "C" fn xmlDictGetUsage(_dict: *const c_void) -> c_uint {
2385 0
2387}
2388
2389#[no_mangle]
2401pub extern "C" fn xmlHashCreate(_size: c_int) -> *mut c_void {
2402 ptr::null_mut()
2404}
2405
2406#[no_mangle]
2414pub extern "C" fn xmlHashCreateDict(_size: c_int, _dict: *mut c_void) -> *mut c_void {
2415 ptr::null_mut()
2417}
2418
2419#[no_mangle]
2427pub extern "C" fn xmlHashFree(
2428 _table: *mut c_void,
2429 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2430) {
2431 }
2433
2434#[no_mangle]
2442pub unsafe extern "C" fn xmlHashAddEntry(
2443 _table: *mut c_void,
2444 _name: *const xmlChar,
2445 _userdata: *mut c_void,
2446) -> c_int {
2447 0
2449}
2450
2451#[no_mangle]
2460pub unsafe extern "C" fn xmlHashAddEntry2(
2461 _table: *mut c_void,
2462 _name: *const xmlChar,
2463 _name2: *const xmlChar,
2464 _userdata: *mut c_void,
2465) -> c_int {
2466 0
2468}
2469
2470#[no_mangle]
2479pub unsafe extern "C" fn xmlHashAddEntry3(
2480 _table: *mut c_void,
2481 _name: *const xmlChar,
2482 _name2: *const xmlChar,
2483 _name3: *const xmlChar,
2484 _userdata: *mut c_void,
2485) -> c_int {
2486 0
2488}
2489
2490#[no_mangle]
2499pub unsafe extern "C" fn xmlHashUpdateEntry(
2500 _table: *mut c_void,
2501 _name: *const xmlChar,
2502 _userdata: *mut c_void,
2503 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2504) -> c_int {
2505 0
2507}
2508
2509#[no_mangle]
2511pub unsafe extern "C" fn xmlHashUpdateEntry2(
2512 _table: *mut c_void,
2513 _name: *const xmlChar,
2514 _name2: *const xmlChar,
2515 _userdata: *mut c_void,
2516 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2517) -> c_int {
2518 0
2520}
2521
2522#[no_mangle]
2524pub unsafe extern "C" fn xmlHashUpdateEntry3(
2525 _table: *mut c_void,
2526 _name: *const xmlChar,
2527 _name2: *const xmlChar,
2528 _name3: *const xmlChar,
2529 _userdata: *mut c_void,
2530 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2531) -> c_int {
2532 0
2534}
2535
2536#[no_mangle]
2544pub unsafe extern "C" fn xmlHashLookup(_table: *mut c_void, _name: *const xmlChar) -> *mut c_void {
2545 ptr::null_mut()
2547}
2548
2549#[no_mangle]
2551pub unsafe extern "C" fn xmlHashLookup2(
2552 _table: *mut c_void,
2553 _name: *const xmlChar,
2554 _name2: *const xmlChar,
2555) -> *mut c_void {
2556 ptr::null_mut()
2558}
2559
2560#[no_mangle]
2562pub unsafe extern "C" fn xmlHashLookup3(
2563 _table: *mut c_void,
2564 _name: *const xmlChar,
2565 _name2: *const xmlChar,
2566 _name3: *const xmlChar,
2567) -> *mut c_void {
2568 ptr::null_mut()
2570}
2571
2572#[no_mangle]
2580pub extern "C" fn xmlHashSize(_table: *mut c_void) -> c_int {
2581 0
2583}
2584
2585#[no_mangle]
2594pub unsafe extern "C" fn xmlHashRemoveEntry(
2595 _table: *mut c_void,
2596 _name: *const xmlChar,
2597 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2598) -> c_int {
2599 0
2601}
2602
2603#[no_mangle]
2605pub unsafe extern "C" fn xmlHashRemoveEntry2(
2606 _table: *mut c_void,
2607 _name: *const xmlChar,
2608 _name2: *const xmlChar,
2609 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2610) -> c_int {
2611 0
2613}
2614
2615#[no_mangle]
2617pub unsafe extern "C" fn xmlHashRemoveEntry3(
2618 _table: *mut c_void,
2619 _name: *const xmlChar,
2620 _name2: *const xmlChar,
2621 _name3: *const xmlChar,
2622 _f: Option<unsafe extern "C" fn(*mut c_void, *mut xmlChar)>,
2623) -> c_int {
2624 0
2626}
2627
2628#[no_mangle]
2636pub extern "C" fn xmlHashScan(
2637 _table: *mut c_void,
2638 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void)>,
2639 _data: *mut c_void,
2640) {
2641 }
2643
2644#[no_mangle]
2646pub extern "C" fn xmlHashScanFull(
2647 _table: *mut c_void,
2648 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar, *mut c_void, *mut c_void)>,
2649 _data: *mut c_void,
2650) {
2651 }
2653
2654#[no_mangle]
2662pub extern "C" fn xmlHashCopy(
2663 _table: *mut c_void,
2664 _f: Option<unsafe extern "C" fn(*mut c_void, *const xmlChar) -> *mut c_void>,
2665) -> *mut c_void {
2666 ptr::null_mut()
2668}
2669
2670#[no_mangle]
2683pub extern "C" fn xmlListCreate(
2684 _deallocator: Option<unsafe extern "C" fn(*mut c_void)>,
2685 _compare: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
2686) -> *mut c_void {
2687 ptr::null_mut()
2689}
2690
2691#[no_mangle]
2699pub extern "C" fn xmlListDelete(_list: *mut c_void) {
2700 }
2702
2703#[no_mangle]
2711pub extern "C" fn xmlListSearch(_list: *mut c_void, _data: *mut c_void) -> *mut c_void {
2712 ptr::null_mut()
2714}
2715
2716#[no_mangle]
2724pub extern "C" fn xmlListWalk(
2725 _list: *mut c_void,
2726 _walker: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
2727 _data: *mut c_void,
2728) {
2729 }
2731
2732#[no_mangle]
2740pub extern "C" fn xmlListPushBack(_list: *mut c_void, _data: *mut c_void) -> c_int {
2741 0
2743}
2744
2745#[no_mangle]
2753pub extern "C" fn xmlListPushFront(_list: *mut c_void, _data: *mut c_void) -> c_int {
2754 0
2756}
2757
2758#[no_mangle]
2760pub extern "C" fn xmlListPopBack(_list: *mut c_void) {
2761 }
2763
2764#[no_mangle]
2766pub extern "C" fn xmlListPopFront(_list: *mut c_void) {
2767 }
2769
2770#[no_mangle]
2778pub extern "C" fn xmlListInsert(_list: *mut c_void, _data: *mut c_void) -> c_int {
2779 0
2781}
2782
2783#[no_mangle]
2785pub extern "C" fn xmlListAppend(_list: *mut c_void, _data: *mut c_void) -> c_int {
2786 0
2788}
2789
2790#[no_mangle]
2792pub extern "C" fn xmlListRemoveFirst(_list: *mut c_void, _data: *mut c_void) -> c_int {
2793 0
2795}
2796
2797#[no_mangle]
2799pub extern "C" fn xmlListRemoveLast(_list: *mut c_void, _data: *mut c_void) -> c_int {
2800 0
2802}
2803
2804#[no_mangle]
2806pub extern "C" fn xmlListRemoveAll(_list: *mut c_void, _data: *mut c_void) -> c_int {
2807 0
2809}
2810
2811#[no_mangle]
2813pub extern "C" fn xmlListClear(_list: *mut c_void) {
2814 }
2816
2817#[no_mangle]
2825pub extern "C" fn xmlListEmpty(_list: *mut c_void) -> c_int {
2826 1
2828}
2829
2830#[no_mangle]
2838pub extern "C" fn xmlListFront(_list: *mut c_void) -> *mut c_void {
2839 ptr::null_mut()
2841}
2842
2843#[no_mangle]
2851pub extern "C" fn xmlListBack(_list: *mut c_void) -> *mut c_void {
2852 ptr::null_mut()
2854}
2855
2856#[no_mangle]
2864pub extern "C" fn xmlListSize(_list: *mut c_void) -> c_int {
2865 0
2867}
2868
2869#[no_mangle]
2871pub extern "C" fn xmlListSort(_list: *mut c_void) {
2872 }
2874
2875#[no_mangle]
2877pub extern "C" fn xmlListReverse(_list: *mut c_void) {
2878 }
2880
2881#[no_mangle]
2883pub extern "C" fn xmlListReverseSplice(_list: *mut c_void, _list2: *mut c_void) {
2884 }
2886
2887#[no_mangle]
2889pub extern "C" fn xmlListMerge(_list: *mut c_void, _list2: *mut c_void) {
2890 }
2892
2893#[no_mangle]
2905pub extern "C" fn xmlBufferCreate() -> *mut _xmlBuffer {
2906 crate::xml::io::buf_create(-1)
2907}
2908
2909#[no_mangle]
2917pub extern "C" fn xmlBufferCreateSize(size: usize) -> *mut _xmlBuffer {
2918 crate::xml::io::buf_create(size as c_int)
2919}
2920
2921#[no_mangle]
2929pub extern "C" fn xmlBufferCreateStatic(mem: *mut c_void, size: usize) -> *mut _xmlBuffer {
2930 if mem.is_null() || size == 0 {
2931 return ptr::null_mut();
2932 }
2933 crate::xml::io::buf_create_static(mem as *const xmlChar, size as c_int)
2934}
2935
2936#[no_mangle]
2944pub extern "C" fn xmlBufferFree(buf: *mut _xmlBuffer) {
2945 crate::xml::io::buf_free(buf)
2946}
2947
2948#[no_mangle]
2956pub extern "C" fn xmlBufferEmpty(buf: *mut _xmlBuffer) {
2957 if buf.is_null() {
2958 return;
2959 }
2960 unsafe {
2961 if !(*buf).content.is_null() {
2962 *(*buf).content = 0;
2963 }
2964 (*buf).use_ = 0;
2965 }
2966}
2967
2968#[no_mangle]
2976pub extern "C" fn xmlBufferContent(buf: *const _xmlBuffer) -> *mut xmlChar {
2977 crate::xml::io::buf_content(buf as *mut _xmlBuffer)
2978}
2979
2980#[no_mangle]
2988pub extern "C" fn xmlBufferLength(buf: *const _xmlBuffer) -> c_int {
2989 crate::xml::io::buf_length(buf as *mut _xmlBuffer)
2990}
2991
2992#[no_mangle]
3000pub unsafe extern "C" fn xmlBufferAdd(
3001 buf: *mut _xmlBuffer,
3002 str: *const xmlChar,
3003 len: c_int,
3004) -> c_int {
3005 crate::xml::io::buf_add(buf, str, len)
3006}
3007
3008#[no_mangle]
3016pub unsafe extern "C" fn xmlBufferAddHead(
3017 buf: *mut _xmlBuffer,
3018 str: *const xmlChar,
3019 len: c_int,
3020) -> c_int {
3021 crate::xml::io::buf_add_head(buf, str, len)
3022}
3023
3024#[no_mangle]
3032pub unsafe extern "C" fn xmlBufferCat(buf: *mut _xmlBuffer, str: *const xmlChar) -> c_int {
3033 if str.is_null() {
3034 return -1;
3035 }
3036 let len = crate::xml::string::xml_strlen(str) as c_int;
3037 crate::xml::io::buf_add(buf, str, len)
3038}
3039
3040#[no_mangle]
3049pub extern "C" fn xmlBufferSetAllocationScheme(buf: *mut _xmlBuffer, scheme: c_int) {
3050 if buf.is_null() {
3051 return;
3052 }
3053 unsafe {
3054 (*buf).alloc = scheme;
3055 }
3056}
3057
3058#[no_mangle]
3066pub extern "C" fn xmlBufferShrink(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3067 if buf.is_null() || len <= 0 {
3068 return 0;
3069 }
3070 unsafe {
3071 let b = &mut *buf;
3072 let shrink_len = (len as c_uint).min(b.use_);
3073 if shrink_len > 0 {
3074 let remaining = b.use_ - shrink_len;
3075 if remaining > 0 {
3076 core::ptr::copy(
3077 b.content.add(shrink_len as usize),
3078 b.content,
3079 remaining as usize,
3080 );
3081 }
3082 *b.content.add(remaining as usize) = 0;
3083 b.use_ = remaining;
3084 }
3085 }
3086 len
3087}
3088
3089#[no_mangle]
3097pub extern "C" fn xmlBufferGrow(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3098 if buf.is_null() || len <= 0 {
3099 return 0;
3100 }
3101 let cur_use = unsafe { (*buf).use_ };
3102 let new_size = cur_use + len as c_uint + 1;
3103 crate::xml::io::buf_grow(buf, new_size)
3104}
3105
3106#[no_mangle]
3114pub extern "C" fn xmlBufferReserve(buf: *mut _xmlBuffer, len: c_int) -> c_int {
3115 xmlBufferGrow(buf, len)
3116}
3117
3118#[no_mangle]
3126pub extern "C" fn xmlBufferDetach(buf: *mut _xmlBuffer) -> *mut xmlChar {
3127 if buf.is_null() {
3128 return ptr::null_mut();
3129 }
3130 unsafe {
3131 let content = (*buf).content;
3132 (*buf).content = ptr::null_mut();
3133 (*buf).use_ = 0;
3134 (*buf).size = 0;
3135 content
3136 }
3137}
3138
3139#[no_mangle]
3151pub extern "C" fn xmlGetCharEncoding(name: *const c_char) -> c_int {
3152 if name.is_null() {
3153 return 0; }
3155 let name_bytes = unsafe {
3156 let len = libc::strlen(name);
3157 core::slice::from_raw_parts(name as *const u8, len)
3158 };
3159 crate::xml::encoding::encoding_from_name(name_bytes) as c_int
3160}
3161
3162#[no_mangle]
3170pub extern "C" fn xmlFindCharEncodingHandler(name: *const c_char) -> *mut c_void {
3171 if name.is_null() {
3172 return ptr::null_mut();
3173 }
3174 crate::xml::encoding::find_encoding_handler(name as *const xmlChar) as *mut c_void
3175}
3176
3177#[no_mangle]
3185pub extern "C" fn xmlCharEncCloseFunc(handler: *mut c_void) -> c_int {
3186 if handler.is_null() {
3187 return -1;
3188 }
3189 unsafe {
3191 let h = handler as *mut crate::abi::structs::_xmlCharEncodingHandler;
3192 if !(*h).name.is_null() {
3193 crate::abi::allocator::xmlFree((*h).name as *mut c_void);
3194 }
3195 crate::abi::allocator::xmlFree(handler);
3196 }
3197 0
3198}
3199
3200#[no_mangle]
3208pub unsafe extern "C" fn xmlCharEncInput(input: *mut _xmlParserInputBuffer, _to: c_int) -> c_int {
3209 if input.is_null() {
3210 return -1;
3211 }
3212 let handler = (*input).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3213 if handler.is_null() {
3214 return -1;
3215 }
3216 let raw = (*input).raw as *mut crate::abi::structs::_xmlBuffer;
3217 let buf = (*input).buffer as *mut crate::abi::structs::_xmlBuffer;
3218 if raw.is_null() || buf.is_null() {
3219 return -1;
3220 }
3221 crate::xml::encoding::char_enc_in(handler, buf, raw)
3222}
3223
3224#[no_mangle]
3232pub unsafe extern "C" fn xmlCharEncOutput(output: *mut _xmlOutputBuffer, _to: c_int) -> c_int {
3233 if output.is_null() {
3234 return -1;
3235 }
3236 let handler = (*output).encoder as *mut crate::abi::structs::_xmlCharEncodingHandler;
3237 if handler.is_null() {
3238 return -1;
3239 }
3240 let buf = (*output).buffer as *mut crate::abi::structs::_xmlBuffer;
3241 let conv = (*output).conv as *mut crate::abi::structs::_xmlBuffer;
3242 if buf.is_null() || conv.is_null() {
3243 return -1;
3244 }
3245 crate::xml::encoding::char_enc_out(handler, conv, buf)
3246}
3247
3248#[no_mangle]
3260pub unsafe extern "C" fn xmlParseURI(str: *const c_char) -> *mut c_void {
3261 crate::xml::uri::xmlParseURI(str)
3262}
3263
3264#[no_mangle]
3272pub unsafe extern "C" fn xmlParseURIRaw(str: *const c_char, raw: c_int) -> *mut c_void {
3273 let _ = raw;
3274 crate::xml::uri::xmlParseURI(str)
3275}
3276
3277#[no_mangle]
3285pub unsafe extern "C" fn xmlFreeURI(uri: *mut c_void) {
3286 crate::xml::uri::xmlFreeURI(uri)
3287}
3288
3289#[no_mangle]
3297pub extern "C" fn xmlCreateURI() -> *mut c_void {
3298 crate::xml::uri::xmlCreateURI()
3299}
3300
3301#[no_mangle]
3309pub unsafe extern "C" fn xmlSaveUri(uri: *mut c_void) -> *mut xmlChar {
3310 crate::xml::uri::xmlSaveUri(uri)
3311}
3312
3313#[no_mangle]
3321pub unsafe extern "C" fn xmlURIEscapeStr(
3322 str: *const xmlChar,
3323 list: *const xmlChar,
3324) -> *mut xmlChar {
3325 crate::xml::uri::xmlURIEscapeStr(str, list)
3326}
3327
3328#[no_mangle]
3336pub unsafe extern "C" fn xmlURIUnescapeString(
3337 str: *const c_char,
3338 len: c_int,
3339 target: *mut c_char,
3340) -> *mut c_char {
3341 crate::xml::uri::xmlURIUnescapeString(str, len, target)
3342}
3343
3344unsafe fn xpath_to_object(val: XPathValue) -> *mut _xmlXPathObject {
3359 let obj = xmlMallocZero(size_of::<_xmlXPathObject>()) as *mut _xmlXPathObject;
3360 if obj.is_null() {
3361 return ptr::null_mut();
3362 }
3363 match val {
3364 XPathValue::NodeSet(ns) => {
3365 (*obj).type_ = xmlXPathObjectType::XPATH_NODESET as c_int;
3366 (*obj).nodesetval = ns.to_raw() as *mut c_void;
3367 }
3368 XPathValue::Boolean(b) => {
3369 (*obj).type_ = xmlXPathObjectType::XPATH_BOOLEAN as c_int;
3370 (*obj).boolval = if b { 1 } else { 0 };
3371 }
3372 XPathValue::Number(n) => {
3373 (*obj).type_ = xmlXPathObjectType::XPATH_NUMBER as c_int;
3374 (*obj).floatval = n;
3375 }
3376 XPathValue::String(s) => {
3377 (*obj).type_ = xmlXPathObjectType::XPATH_STRING as c_int;
3378 let bytes = s.as_bytes();
3379 let len = bytes.len();
3380 let buf = xmlMalloc(len + 1) as *mut xmlChar;
3381 if !buf.is_null() {
3382 ptr::copy_nonoverlapping(bytes.as_ptr(), buf, len);
3383 *buf.add(len) = 0; }
3385 (*obj).stringval = buf;
3386 }
3387 }
3388 obj
3389}
3390
3391unsafe fn object_to_xpathvalue(obj: *mut _xmlXPathObject) -> XPathValue {
3398 let typ = (*obj).type_;
3399 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3400 let ns_ptr = (*obj).nodesetval as *mut _xmlNodeSet;
3401 if ns_ptr.is_null() {
3402 return XPathValue::NodeSet(NodeSet::new());
3403 }
3404 let node_nr = (*ns_ptr).nodeNr;
3405 let node_tab = (*ns_ptr).nodeTab;
3406 let mut ns = NodeSet::new();
3407 if !node_tab.is_null() {
3408 for i in 0..node_nr as isize {
3409 let node = *node_tab.add(i as usize);
3410 ns.push(node);
3411 }
3412 }
3413 XPathValue::NodeSet(ns)
3414 } else if typ == xmlXPathObjectType::XPATH_BOOLEAN as c_int {
3415 XPathValue::Boolean((*obj).boolval != 0)
3416 } else if typ == xmlXPathObjectType::XPATH_NUMBER as c_int {
3417 XPathValue::Number((*obj).floatval)
3418 } else if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3419 let s_ptr = (*obj).stringval;
3420 if s_ptr.is_null() {
3421 XPathValue::String(String::new())
3422 } else {
3423 let s = CStr::from_ptr(s_ptr as *const c_char)
3424 .to_string_lossy()
3425 .into_owned();
3426 XPathValue::String(s)
3427 }
3428 } else {
3429 XPathValue::Boolean(false)
3431 }
3432}
3433
3434static COMPILED_EXPRS: Lazy<Mutex<HashMap<u64, Box<CompiledExpr>>>> =
3440 Lazy::new(|| Mutex::new(HashMap::new()));
3441static NEXT_COMPILED_KEY: Lazy<Mutex<u64>> = Lazy::new(|| Mutex::new(1));
3442
3443type CXPathFunc = unsafe extern "C" fn(*mut c_void, c_int);
3453
3454#[derive(Clone, Copy, PartialEq, Eq, Hash)]
3457struct SendSyncPtr(*mut c_void);
3458unsafe impl Send for SendSyncPtr {}
3459unsafe impl Sync for SendSyncPtr {}
3460
3461static C_FUNCTIONS: Lazy<Mutex<HashMap<(SendSyncPtr, String), CXPathFunc>>> =
3462 Lazy::new(|| Mutex::new(HashMap::new()));
3463
3464fn c_func_stub(_ctx: &mut XPathContext, _args: &[XPathValue]) -> Result<XPathValue, String> {
3469 Err(
3470 "C extension function cannot be called from Rust evaluator without a parser-context bridge"
3471 .to_string(),
3472 )
3473}
3474
3475#[no_mangle]
3488pub unsafe extern "C" fn xmlXPathNewContext(doc: *mut _xmlDoc) -> *mut _xmlXPathContext {
3489 let ctxt = xmlMallocZero(size_of::<_xmlXPathContext>()) as *mut _xmlXPathContext;
3490 if ctxt.is_null() {
3491 return ptr::null_mut();
3492 }
3493
3494 (*ctxt).doc = doc;
3496 (*ctxt).node = ptr::null_mut();
3497 (*ctxt).contextSize = 1;
3498 (*ctxt).proximityPosition = 1;
3499
3500 let internal = Box::new(XPathContext::new(doc));
3502 (*ctxt).extra = Box::into_raw(internal) as *mut c_void;
3503
3504 ctxt
3505}
3506
3507#[no_mangle]
3515pub unsafe extern "C" fn xmlXPathFreeContext(ctxt: *mut _xmlXPathContext) {
3516 if ctxt.is_null() {
3517 return;
3518 }
3519 if !(*ctxt).extra.is_null() {
3521 let _ = Box::from_raw((*ctxt).extra as *mut XPathContext);
3522 (*ctxt).extra = ptr::null_mut();
3523 }
3524 xmlFree(ctxt as *mut c_void);
3526}
3527
3528#[no_mangle]
3537pub unsafe extern "C" fn xmlXPathEvalExpression(
3538 str_: *const xmlChar,
3539 ctxt: *mut _xmlXPathContext,
3540) -> *mut _xmlXPathObject {
3541 if str_.is_null() || ctxt.is_null() {
3542 return ptr::null_mut();
3543 }
3544 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
3545 Ok(s) => s,
3546 Err(_) => return ptr::null_mut(),
3547 };
3548 let internal = (*ctxt).extra as *mut XPathContext;
3549 if internal.is_null() {
3550 return ptr::null_mut();
3551 }
3552 let internal = &mut *internal;
3553
3554 match crate::xml::xpath::evaluate_str(expr_str, internal) {
3555 Some(val) => xpath_to_object(val),
3556 None => ptr::null_mut(),
3557 }
3558}
3559
3560#[no_mangle]
3568pub unsafe extern "C" fn xmlXPathEval(
3569 str_: *const xmlChar,
3570 ctxt: *mut _xmlXPathContext,
3571) -> *mut _xmlXPathObject {
3572 xmlXPathEvalExpression(str_, ctxt)
3573}
3574
3575#[no_mangle]
3586pub unsafe extern "C" fn xmlXPathFreeObject(obj: *mut _xmlXPathObject) {
3587 if obj.is_null() {
3588 return;
3589 }
3590 let typ = (*obj).type_;
3591 if typ == xmlXPathObjectType::XPATH_STRING as c_int {
3593 if !(*obj).stringval.is_null() {
3594 xmlFree((*obj).stringval as *mut c_void);
3595 (*obj).stringval = ptr::null_mut();
3596 }
3597 }
3598 if typ == xmlXPathObjectType::XPATH_NODESET as c_int {
3600 let ns = (*obj).nodesetval as *mut _xmlNodeSet;
3601 if !ns.is_null() {
3602 if !(*ns).nodeTab.is_null() {
3603 xmlFree((*ns).nodeTab as *mut c_void);
3604 }
3605 xmlFree(ns as *mut c_void);
3606 }
3607 (*obj).nodesetval = ptr::null_mut();
3608 }
3609 xmlFree(obj as *mut c_void);
3610}
3611
3612#[no_mangle]
3623pub unsafe extern "C" fn xmlXPathCompile(str_: *const xmlChar) -> *mut c_void {
3624 if str_.is_null() {
3625 return ptr::null_mut();
3626 }
3627 let expr_str = match CStr::from_ptr(str_ as *const c_char).to_str() {
3628 Ok(s) => s,
3629 Err(_) => return ptr::null_mut(),
3630 };
3631
3632 match crate::xml::xpath::compile(expr_str) {
3633 Some(compiled) => {
3634 let mut map = COMPILED_EXPRS.lock();
3635 let mut counter = NEXT_COMPILED_KEY.lock();
3636 let key = *counter;
3637 *counter += 1;
3638 map.insert(key, Box::new(compiled));
3639 key as *mut c_void
3640 }
3641 None => ptr::null_mut(),
3642 }
3643}
3644
3645#[no_mangle]
3653pub unsafe extern "C" fn xmlXPathFreeCompExpr(comp: *mut c_void) {
3654 if comp.is_null() {
3655 return;
3656 }
3657 let mut map = COMPILED_EXPRS.lock();
3658 map.remove(&(comp as u64));
3659}
3660
3661#[no_mangle]
3670pub unsafe extern "C" fn xmlXPathRegisterNs(
3671 ctxt: *mut _xmlXPathContext,
3672 prefix: *const xmlChar,
3673 ns_uri: *const xmlChar,
3674) -> c_int {
3675 if ctxt.is_null() || prefix.is_null() || ns_uri.is_null() {
3676 return -1;
3677 }
3678 let internal = (*ctxt).extra as *mut XPathContext;
3679 if internal.is_null() {
3680 return -1;
3681 }
3682 let internal = &mut *internal;
3683
3684 let prefix_str = match CStr::from_ptr(prefix as *const c_char).to_str() {
3685 Ok(s) => s,
3686 Err(_) => return -1,
3687 };
3688 let uri_str = match CStr::from_ptr(ns_uri as *const c_char).to_str() {
3689 Ok(s) => s,
3690 Err(_) => return -1,
3691 };
3692
3693 internal.register_namespace(prefix_str, uri_str);
3694 0
3695}
3696
3697#[no_mangle]
3711pub unsafe extern "C" fn xmlXPathRegisterFunc(
3712 ctxt: *mut _xmlXPathContext,
3713 name: *const xmlChar,
3714 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
3715) -> c_int {
3716 if ctxt.is_null() || name.is_null() {
3717 return -1;
3718 }
3719 let internal = (*ctxt).extra as *mut XPathContext;
3720 if internal.is_null() {
3721 return -1;
3722 }
3723 let internal = &mut *internal;
3724
3725 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
3726 Ok(s) => s,
3727 Err(_) => return -1,
3728 };
3729
3730 if let Some(func) = f {
3731 let key = (SendSyncPtr((*ctxt).extra), name_str.to_string());
3733 C_FUNCTIONS.lock().insert(key, func);
3734 internal.register_function(name_str, c_func_stub);
3736 }
3737 0
3738}
3739
3740#[no_mangle]
3750pub unsafe extern "C" fn xmlXPathRegisterFuncNS(
3751 ctxt: *mut _xmlXPathContext,
3752 name: *const xmlChar,
3753 ns_uri: *const xmlChar,
3754 f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
3755) -> c_int {
3756 if ctxt.is_null() || name.is_null() {
3757 return -1;
3758 }
3759 let internal = (*ctxt).extra as *mut XPathContext;
3760 if internal.is_null() {
3761 return -1;
3762 }
3763 let internal = &mut *internal;
3764
3765 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
3766 Ok(s) => s,
3767 Err(_) => return -1,
3768 };
3769 let ns_str = if ns_uri.is_null() {
3770 String::new()
3771 } else {
3772 match CStr::from_ptr(ns_uri as *const c_char).to_str() {
3773 Ok(s) => s.to_string(),
3774 Err(_) => return -1,
3775 }
3776 };
3777
3778 let qualified = if ns_str.is_empty() {
3780 name_str.to_string()
3781 } else {
3782 format!("{{{}}}{}", ns_str, name_str)
3783 };
3784
3785 if let Some(func) = f {
3786 let key = (SendSyncPtr((*ctxt).extra), qualified.clone());
3787 C_FUNCTIONS.lock().insert(key, func);
3788 internal.register_function(&qualified, c_func_stub);
3789 }
3790 0
3791}
3792
3793#[no_mangle]
3802pub unsafe extern "C" fn xmlXPathRegisterVariable(
3803 ctxt: *mut _xmlXPathContext,
3804 name: *const xmlChar,
3805 value: *mut _xmlXPathObject,
3806) -> c_int {
3807 if ctxt.is_null() || name.is_null() || value.is_null() {
3808 return -1;
3809 }
3810 let internal = (*ctxt).extra as *mut XPathContext;
3811 if internal.is_null() {
3812 return -1;
3813 }
3814 let internal = &mut *internal;
3815
3816 let name_str = match CStr::from_ptr(name as *const c_char).to_str() {
3817 Ok(s) => s,
3818 Err(_) => return -1,
3819 };
3820
3821 let xpath_val = object_to_xpathvalue(value);
3822 internal.register_variable(name_str, xpath_val);
3823 0
3824}
3825
3826#[no_mangle]
3834pub unsafe extern "C" fn xmlXPathNewNodeSet(val: *mut _xmlNode) -> *mut _xmlXPathObject {
3835 let ns = if val.is_null() {
3836 NodeSet::new()
3837 } else {
3838 NodeSet::singleton(val)
3839 };
3840 xpath_to_object(XPathValue::NodeSet(ns))
3841}
3842
3843#[no_mangle]
3851pub unsafe extern "C" fn xmlXPathNewCString(val: *const xmlChar) -> *mut _xmlXPathObject {
3852 if val.is_null() {
3853 return xpath_to_object(XPathValue::String(String::new()));
3854 }
3855 let s = match CStr::from_ptr(val as *const c_char).to_str() {
3856 Ok(s) => s.to_string(),
3857 Err(_) => return ptr::null_mut(),
3858 };
3859 xpath_to_object(XPathValue::String(s))
3860}
3861
3862#[no_mangle]
3870pub extern "C" fn xmlXPathNewFloat(val: f64) -> *mut _xmlXPathObject {
3871 unsafe { xpath_to_object(XPathValue::Number(val)) }
3872}
3873
3874#[no_mangle]
3882pub extern "C" fn xmlXPathNewBoolean(val: c_int) -> *mut _xmlXPathObject {
3883 unsafe { xpath_to_object(XPathValue::Boolean(val != 0)) }
3884}
3885
3886#[no_mangle]
3900pub unsafe extern "C" fn xmlXPtrEval(expr: *const c_char, doc: *mut _xmlDoc) -> *mut _xmlNode {
3901 crate::xml::xpointer::xmlXPtrEval(expr, doc)
3902}
3903
3904#[no_mangle]
3916pub unsafe extern "C" fn xmlXIncludeProcess(doc: *mut _xmlDoc) -> c_int {
3917 crate::xml::xinclude::xinclude_process(doc)
3918}
3919
3920#[no_mangle]
3928pub unsafe extern "C" fn xmlXIncludeProcessFlags(doc: *mut _xmlDoc, flags: c_int) -> c_int {
3929 crate::xml::xinclude::xinclude_process_flags(doc, flags)
3930}
3931
3932#[no_mangle]
3944pub extern "C" fn xmlCatalogLoad(catalogs: *const c_char) -> *mut c_void {
3945 if catalogs.is_null() {
3946 return ptr::null_mut();
3947 }
3948 crate::xml::catalog::load_catalog(catalogs)
3949}
3950
3951#[no_mangle]
3959pub unsafe extern "C" fn xmlCatalogResolvePublic(pubID: *const xmlChar) -> *mut xmlChar {
3960 if pubID.is_null() {
3961 return ptr::null_mut();
3962 }
3963 crate::xml::catalog::resolve_public(pubID)
3964}
3965
3966#[no_mangle]
3974pub unsafe extern "C" fn xmlCatalogResolveSystem(sysID: *const xmlChar) -> *mut xmlChar {
3975 if sysID.is_null() {
3976 return ptr::null_mut();
3977 }
3978 crate::xml::catalog::resolve_system(sysID)
3979}
3980
3981#[no_mangle]
3989pub unsafe extern "C" fn xmlCatalogResolveURI(URI: *const xmlChar) -> *mut xmlChar {
3990 if URI.is_null() {
3991 return ptr::null_mut();
3992 }
3993 crate::xml::catalog::resolve_uri(URI)
3994}
3995
3996#[no_mangle]
4004pub extern "C" fn xmlCatalogSetDefaults(allow: c_int) {
4005 crate::xml::catalog::set_defaults(allow)
4006}
4007
4008#[no_mangle]
4016pub extern "C" fn xmlCatalogGetDefaults() -> c_int {
4017 crate::xml::catalog::get_defaults()
4018}
4019
4020#[no_mangle]
4028pub unsafe extern "C" fn xmlCatalogAdd(
4029 type_: *const xmlChar,
4030 orig: *const xmlChar,
4031 replace: *const xmlChar,
4032) -> c_int {
4033 if type_.is_null() || orig.is_null() || replace.is_null() {
4034 return -1;
4035 }
4036 crate::xml::catalog::add(type_, orig, replace)
4037}
4038
4039#[no_mangle]
4047pub unsafe extern "C" fn xmlCatalogRemove(value: *const xmlChar) -> c_int {
4048 if value.is_null() {
4049 return 0;
4050 }
4051 crate::xml::catalog::remove(value)
4052}
4053
4054#[no_mangle]
4062pub extern "C" fn xmlCatalogCleanup() {
4063 crate::xml::catalog::cleanup();
4064}
4065
4066#[no_mangle]
4074pub extern "C" fn xmlCatalogConvert() -> *mut _xmlDoc {
4075 unsafe { crate::xml::catalog::convert() }
4077}
4078
4079#[no_mangle]
4091pub unsafe extern "C" fn htmlParseFile(
4092 _filename: *const c_char,
4093 _encoding: *const c_char,
4094) -> *mut _xmlDoc {
4095 ptr::null_mut()
4097}
4098
4099#[no_mangle]
4107pub unsafe extern "C" fn htmlParseMemory(_buffer: *const c_char, _size: c_int) -> *mut _xmlDoc {
4108 ptr::null_mut()
4110}
4111
4112#[no_mangle]
4120pub unsafe extern "C" fn htmlParseDoc(
4121 _cur: *const xmlChar,
4122 _encoding: *const c_char,
4123) -> *mut _xmlDoc {
4124 ptr::null_mut()
4126}
4127
4128#[no_mangle]
4137pub unsafe extern "C" fn htmlCreateFileParserCtxt(
4138 _filename: *const c_char,
4139 _encoding: *const c_char,
4140) -> *mut c_void {
4141 ptr::null_mut()
4143}
4144
4145#[no_mangle]
4153pub extern "C" fn htmlFreeParserCtxt(_ctxt: *mut c_void) {
4154 }
4156
4157#[no_mangle]
4165pub extern "C" fn htmlInitParser() {
4166 }
4168
4169#[no_mangle]
4177pub extern "C" fn htmlCleanupParser() {
4178 }
4180
4181#[no_mangle]
4193pub unsafe extern "C" fn xmlDebugDumpDocument(_output: *mut c_void, _doc: *mut _xmlDoc) {
4194 }
4196
4197#[no_mangle]
4205pub unsafe extern "C" fn xmlDebugDumpNode(_output: *mut c_void, _node: *mut _xmlNode) {
4206 }
4208
4209#[no_mangle]
4217pub unsafe extern "C" fn xmlDebugDumpNodeList(_output: *mut c_void, _node: *mut _xmlNode) {
4218 }
4220
4221#[no_mangle]
4229pub extern "C" fn xmlGetBinaryPath() -> *mut c_char {
4230 ptr::null_mut()
4232}
4233
4234#[no_mangle]
4242pub extern "C" fn xmlGetHomeOfBinary() -> *mut c_char {
4243 ptr::null_mut()
4245}