use crate::abi::callbacks::*;
use crate::abi::constants::XML_SAX2_MAGIC;
use crate::abi::structs::*;
use crate::abi::types::*;
use core::ptr;
use std::os::raw::{c_char, c_int, c_uint, c_void};
pub(crate) struct SaxDispatcher;
#[allow(non_snake_case)]
impl SaxDispatcher {
#[inline]
pub unsafe fn internal_subset(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
ext_id: *const xmlChar,
sys_id: *const xmlChar,
) {
if let Some(cb) = sax.internalSubset {
unsafe { cb(ctx, name, ext_id, sys_id) };
}
}
#[inline]
pub unsafe fn is_standalone(sax: &_xmlSAXHandler, ctx: *mut c_void) -> c_int {
if let Some(cb) = sax.isStandalone {
unsafe { cb(ctx) }
} else {
-1
}
}
#[inline]
pub unsafe fn has_internal_subset(sax: &_xmlSAXHandler, ctx: *mut c_void) -> c_int {
if let Some(cb) = sax.hasInternalSubset {
unsafe { cb(ctx) }
} else {
0
}
}
#[inline]
pub unsafe fn has_external_subset(sax: &_xmlSAXHandler, ctx: *mut c_void) -> c_int {
if let Some(cb) = sax.hasExternalSubset {
unsafe { cb(ctx) }
} else {
0
}
}
#[inline]
pub unsafe fn resolve_entity(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
pub_id: *const xmlChar,
sys_id: *const xmlChar,
) -> *mut _xmlParserInput {
if let Some(cb) = sax.resolveEntity {
unsafe { cb(ctx, pub_id, sys_id) }
} else {
ptr::null_mut()
}
}
#[inline]
pub unsafe fn get_entity(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
) -> *mut _xmlEntity {
if let Some(cb) = sax.getEntity {
unsafe { cb(ctx, name) }
} else {
ptr::null_mut()
}
}
#[inline]
pub unsafe fn entity_decl(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
type_: c_int,
pub_id: *const xmlChar,
sys_id: *const xmlChar,
content: *mut xmlChar,
) {
if let Some(cb) = sax.entityDecl {
unsafe { cb(ctx, name, type_, pub_id, sys_id, content) };
}
}
#[inline]
pub unsafe fn notation_decl(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
pub_id: *const xmlChar,
sys_id: *const xmlChar,
) {
if let Some(cb) = sax.notationDecl {
unsafe { cb(ctx, name, pub_id, sys_id) };
}
}
#[inline]
pub unsafe fn attribute_decl(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
elem: *const xmlChar,
fullname: *const xmlChar,
type_: c_int,
def: c_int,
default_value: *const xmlChar,
tree: *mut _xmlEnumeration,
) {
if let Some(cb) = sax.attributeDecl {
unsafe { cb(ctx, elem, fullname, type_, def, default_value, tree) };
}
}
#[inline]
pub unsafe fn element_decl(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
type_: c_int,
content: *mut _xmlElementContent,
) {
if let Some(cb) = sax.elementDecl {
unsafe { cb(ctx, name, type_, content) };
}
}
#[inline]
pub unsafe fn unparsed_entity_decl(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
pub_id: *const xmlChar,
sys_id: *const xmlChar,
notation: *const xmlChar,
) {
if let Some(cb) = sax.unparsedEntityDecl {
unsafe { cb(ctx, name, pub_id, sys_id, notation) };
}
}
#[inline]
pub unsafe fn set_document_locator(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
loc: *mut _xmlSAXLocator,
) {
if let Some(cb) = sax.setDocumentLocator {
unsafe { cb(ctx, loc) };
}
}
#[inline]
pub unsafe fn start_document(sax: &_xmlSAXHandler, ctx: *mut c_void) {
if let Some(cb) = sax.startDocument {
unsafe { cb(ctx) };
}
}
#[inline]
pub unsafe fn end_document(sax: &_xmlSAXHandler, ctx: *mut c_void) {
if let Some(cb) = sax.endDocument {
unsafe { cb(ctx) };
}
}
#[inline]
pub unsafe fn start_element(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
localname: *const xmlChar,
prefix: *const xmlChar,
URI: *const xmlChar,
nb_namespaces: c_int,
namespaces: *mut *const xmlChar,
nb_attributes: c_int,
nb_defaulted: c_int,
attributes: *mut *const xmlChar,
) {
if let Some(cb) = sax.startElementNs {
unsafe {
cb(
ctx,
localname,
prefix,
URI,
nb_namespaces,
namespaces,
nb_attributes,
nb_defaulted,
attributes,
)
};
} else if let Some(cb) = sax.startElement {
unsafe { cb(ctx, localname, ptr::null_mut()) };
}
}
#[inline]
pub unsafe fn end_element(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
localname: *const xmlChar,
prefix: *const xmlChar,
URI: *const xmlChar,
) {
if let Some(cb) = sax.endElementNs {
unsafe { cb(ctx, localname, prefix, URI) };
} else if let Some(cb) = sax.endElement {
unsafe { cb(ctx, localname) };
}
}
#[inline]
pub unsafe fn characters(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
ch: *const xmlChar,
len: c_int,
) {
if let Some(cb) = sax.characters {
unsafe { cb(ctx, ch, len) };
}
}
#[inline]
pub unsafe fn ignorable_whitespace(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
ch: *const xmlChar,
len: c_int,
) {
if let Some(cb) = sax.ignorableWhitespace {
unsafe { cb(ctx, ch, len) };
}
}
#[inline]
pub unsafe fn processing_instruction(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
target: *const xmlChar,
data: *const xmlChar,
) {
if let Some(cb) = sax.processingInstruction {
unsafe { cb(ctx, target, data) };
}
}
#[inline]
pub unsafe fn comment(sax: &_xmlSAXHandler, ctx: *mut c_void, value: *const xmlChar) {
if let Some(cb) = sax.comment {
unsafe { cb(ctx, value) };
}
}
#[inline]
pub unsafe fn warning(sax: &_xmlSAXHandler, ctx: *mut c_void, msg: *const c_char) {
if let Some(cb) = sax.warning {
unsafe { cb(ctx, msg) };
}
}
#[inline]
pub unsafe fn error(sax: &_xmlSAXHandler, ctx: *mut c_void, msg: *const c_char) {
if let Some(cb) = sax.error {
unsafe { cb(ctx, msg) };
}
}
#[inline]
pub unsafe fn fatal_error(sax: &_xmlSAXHandler, ctx: *mut c_void, msg: *const c_char) {
if let Some(cb) = sax.fatalError {
unsafe { cb(ctx, msg) };
}
}
#[inline]
pub unsafe fn cdata_block(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
value: *const xmlChar,
len: c_int,
) {
if let Some(cb) = sax.cdataBlock {
unsafe { cb(ctx, value, len) };
}
}
#[inline]
pub unsafe fn reference(sax: &_xmlSAXHandler, ctx: *mut c_void, name: *const xmlChar) {
if let Some(cb) = sax.reference {
unsafe { cb(ctx, name) };
}
}
#[inline]
pub unsafe fn get_parameter_entity(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
) -> *mut _xmlEntity {
if let Some(cb) = sax.getParameterEntity {
unsafe { cb(ctx, name) }
} else {
ptr::null_mut()
}
}
#[inline]
pub unsafe fn external_subset(
sax: &_xmlSAXHandler,
ctx: *mut c_void,
name: *const xmlChar,
ext_id: *const xmlChar,
sys_id: *const xmlChar,
) {
if let Some(cb) = sax.externalSubset {
unsafe { cb(ctx, name, ext_id, sys_id) };
}
}
#[inline]
pub unsafe fn structured_error(sax: &_xmlSAXHandler, ctx: *mut c_void, error: *mut _xmlError) {
if let Some(cb) = sax.serror {
unsafe { cb(ctx, error) };
}
}
}
#[allow(non_snake_case)]
pub unsafe fn xmlSAX2InitDefaultSAXHandler(sax: *mut _xmlSAXHandler) {
use super::default::default_sax_handler as dflt;
if sax.is_null() {
return;
}
unsafe {
let h = &mut *sax;
h.internalSubset = Some(dflt::internalSubset as internalSubsetSAXFunc);
h.isStandalone = Some(dflt::isStandalone as isStandaloneSAXFunc);
h.hasInternalSubset = Some(dflt::hasInternalSubset as hasInternalSubsetSAXFunc);
h.hasExternalSubset = Some(dflt::hasExternalSubset as hasExternalSubsetSAXFunc);
h.resolveEntity = Some(dflt::resolveEntity as resolveEntitySAXFunc);
h.getEntity = Some(dflt::getEntity as getEntitySAXFunc);
h.entityDecl = Some(dflt::entityDecl as entityDeclSAXFunc);
h.notationDecl = Some(dflt::notationDecl as notationDeclSAXFunc);
h.attributeDecl = Some(dflt::attributeDecl as attributeDeclSAXFunc);
h.elementDecl = Some(dflt::elementDecl as elementDeclSAXFunc);
h.unparsedEntityDecl = Some(dflt::unparsedEntityDecl as unparsedEntityDeclSAXFunc);
h.setDocumentLocator = Some(dflt::setDocumentLocator as setDocumentLocatorSAXFunc);
h.startDocument = Some(dflt::startDocument as startDocumentSAXFunc);
h.endDocument = Some(dflt::endDocument as endDocumentSAXFunc);
h.startElement = None; h.endElement = None; h.reference = Some(dflt::reference as referenceSAXFunc);
h.characters = Some(dflt::characters as charactersSAXFunc);
h.ignorableWhitespace = Some(dflt::ignorableWhitespace as ignorableWhitespaceSAXFunc);
h.processingInstruction = Some(dflt::processingInstruction as processingInstructionSAXFunc);
h.comment = Some(dflt::comment as commentSAXFunc);
h.warning = Some(dflt::warning as warningSAXFunc);
h.error = Some(dflt::error as errorSAXFunc);
h.fatalError = Some(dflt::fatalError as fatalErrorSAXFunc);
h.getParameterEntity = Some(dflt::getParameterEntity as getParameterEntitySAXFunc);
h.cdataBlock = Some(dflt::cdataBlock as cdataBlockSAXFunc);
h.externalSubset = Some(dflt::externalSubset as externalSubsetSAXFunc);
h.initialized = XML_SAX2_MAGIC as c_uint;
h._private = ptr::null_mut();
h.startElementNs = Some(dflt::startElementNs as startElementNsSAX2Func);
h.endElementNs = Some(dflt::endElementNs as endElementNsSAX2Func);
h.serror = None;
}
}