| 1 |
// Copyright 2023 The Servo Project Developers. See the COPYRIGHT |
| 2 |
// file at the top-level directory of this distribution. |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 5 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 6 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 |
// option. This file may not be copied, modified, or distributed |
| 8 |
// except according to those terms. |
| 9 |
|
| 10 |
use std::os::raw::c_void; |
| 11 |
|
| 12 |
use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeID}; |
| 13 |
use crate::data::CFDataRef; |
| 14 |
use crate::dictionary::CFDictionaryRef; |
| 15 |
use crate::string::CFStringRef; |
| 16 |
use crate::url::CFURLRef; |
| 17 |
use crate::xml_node::{CFXMLExternalID, CFXMLNodeRef, CFXMLTreeRef}; |
| 18 |
|
| 19 |
#[repr(C)] |
| 20 |
pub struct __CFXMLParser(c_void); |
| 21 |
|
| 22 |
pub type CFXMLParserRef = *mut __CFXMLParser; |
| 23 |
|
| 24 |
pub type CFXMLParserOptions = CFOptionFlags; |
| 25 |
pub const kCFXMLParserValidateDocument: CFXMLParserOptions = 1 << 0; |
| 26 |
pub const kCFXMLParserSkipMetaData: CFXMLParserOptions = 1 << 1; |
| 27 |
pub const kCFXMLParserReplacePhysicalEntities: CFXMLParserOptions = 1 << 2; |
| 28 |
pub const kCFXMLParserSkipWhitespace: CFXMLParserOptions = 1 << 3; |
| 29 |
pub const kCFXMLParserResolveExternalEntities: CFXMLParserOptions = 1 << 4; |
| 30 |
pub const kCFXMLParserAddImpliedAttributes: CFXMLParserOptions = 1 << 5; |
| 31 |
pub const kCFXMLParserAllOptions: CFXMLParserOptions = 0x00FFFFFF; |
| 32 |
pub const kCFXMLParserNoOptions: CFXMLParserOptions = 0; |
| 33 |
|
| 34 |
pub type CFXMLParserStatusCode = CFIndex; |
| 35 |
pub const kCFXMLStatusParseNotBegun: CFIndex = -2; |
| 36 |
pub const kCFXMLStatusParseInProgress: CFIndex = -1; |
| 37 |
pub const kCFXMLStatusParseSuccessful: CFIndex = 0; |
| 38 |
pub const kCFXMLErrorUnexpectedEOF: CFIndex = 1; |
| 39 |
pub const kCFXMLErrorUnknownEncoding: CFIndex = 2; |
| 40 |
pub const kCFXMLErrorEncodingConversionFailure: CFIndex = 3; |
| 41 |
pub const kCFXMLErrorMalformedProcessingInstruction: CFIndex = 4; |
| 42 |
pub const kCFXMLErrorMalformedDTD: CFIndex = 5; |
| 43 |
pub const kCFXMLErrorMalformedName: CFIndex = 6; |
| 44 |
pub const kCFXMLErrorMalformedCDSect: CFIndex = 7; |
| 45 |
pub const kCFXMLErrorMalformedCloseTag: CFIndex = 8; |
| 46 |
pub const kCFXMLErrorMalformedStartTag: CFIndex = 9; |
| 47 |
pub const kCFXMLErrorMalformedDocument: CFIndex = 10; |
| 48 |
pub const kCFXMLErrorElementlessDocument: CFIndex = 11; |
| 49 |
pub const kCFXMLErrorMalformedComment: CFIndex = 12; |
| 50 |
pub const kCFXMLErrorMalformedCharacterReference: CFIndex = 13; |
| 51 |
pub const kCFXMLErrorMalformedParsedCharacterData: CFIndex = 14; |
| 52 |
pub const kCFXMLErrorNoData: CFIndex = 15; |
| 53 |
|
| 54 |
pub type CFXMLParserCreateXMLStructureCallBack = |
| 55 |
extern "C" fn(parser: CFXMLParserRef, nodeDesc: CFXMLNodeRef, info: *mut c_void) -> *mut c_void; |
| 56 |
pub type CFXMLParserAddChildCallBack = extern "C" fn( |
| 57 |
parser: CFXMLParserRef, |
| 58 |
parent: *mut c_void, |
| 59 |
child: *mut c_void, |
| 60 |
info: *mut c_void, |
| 61 |
); |
| 62 |
pub type CFXMLParserEndXMLStructureCallBack = |
| 63 |
extern "C" fn(parser: CFXMLParserRef, xmlType: *mut c_void, info: *mut c_void); |
| 64 |
pub type CFXMLParserResolveExternalEntityCallBack = extern "C" fn( |
| 65 |
parser: CFXMLParserRef, |
| 66 |
extID: *mut CFXMLExternalID, |
| 67 |
info: *mut c_void, |
| 68 |
) -> CFDataRef; |
| 69 |
pub type CFXMLParserHandleErrorCallBack = extern "C" fn( |
| 70 |
parser: CFXMLParserRef, |
| 71 |
error: CFXMLParserStatusCode, |
| 72 |
info: *mut c_void, |
| 73 |
) -> Boolean; |
| 74 |
|
| 75 |
#[repr(C)] |
| 76 |
#[derive(Debug, Clone, Copy)] |
| 77 |
pub struct CFXMLParserCallBacks { |
| 78 |
pub version: CFIndex, |
| 79 |
pub createXMLStructure: CFXMLParserCreateXMLStructureCallBack, |
| 80 |
pub addChild: CFXMLParserAddChildCallBack, |
| 81 |
pub endXMLStructure: CFXMLParserEndXMLStructureCallBack, |
| 82 |
pub resolveExternalEntity: CFXMLParserResolveExternalEntityCallBack, |
| 83 |
pub handleError: CFXMLParserHandleErrorCallBack, |
| 84 |
} |
| 85 |
|
| 86 |
pub type CFXMLParserRetainCallBack = extern "C" fn(info: *const c_void) -> *const c_void; |
| 87 |
pub type CFXMLParserReleaseCallBack = extern "C" fn(info: *const c_void); |
| 88 |
pub type CFXMLParserCopyDescriptionCallBack = extern "C" fn(info: *const c_void) -> CFStringRef; |
| 89 |
|
| 90 |
#[repr(C)] |
| 91 |
#[derive(Debug, Clone, Copy)] |
| 92 |
pub struct CFXMLParserContext { |
| 93 |
pub version: CFIndex, |
| 94 |
pub info: *mut c_void, |
| 95 |
pub retain: CFXMLParserRetainCallBack, |
| 96 |
pub release: CFXMLParserReleaseCallBack, |
| 97 |
pub copyDescription: CFXMLParserCopyDescriptionCallBack, |
| 98 |
} |
| 99 |
|
| 100 |
extern "C" { |
| 101 |
/* |
| 102 |
* CFXMLParser.h |
| 103 |
*/ |
| 104 |
|
| 105 |
pub static kCFXMLTreeErrorDescription: CFStringRef; |
| 106 |
pub static kCFXMLTreeErrorLineNumber: CFStringRef; |
| 107 |
pub static kCFXMLTreeErrorLocation: CFStringRef; |
| 108 |
pub static kCFXMLTreeErrorStatusCode: CFStringRef; |
| 109 |
|
| 110 |
pub fn CFXMLParserGetTypeID() -> CFTypeID; |
| 111 |
pub fn CFXMLParserCreate( |
| 112 |
allocator: CFAllocatorRef, |
| 113 |
xmlData: CFDataRef, |
| 114 |
dataSource: CFURLRef, |
| 115 |
parseOptions: CFOptionFlags, |
| 116 |
versionOfNodes: CFIndex, |
| 117 |
callBacks: *mut CFXMLParserCallBacks, |
| 118 |
context: *mut CFXMLParserContext, |
| 119 |
) -> CFXMLParserRef; |
| 120 |
pub fn CFXMLParserCreateWithDataFromURL( |
| 121 |
allocator: CFAllocatorRef, |
| 122 |
dataSource: CFURLRef, |
| 123 |
parseOptions: CFOptionFlags, |
| 124 |
versionOfNodes: CFIndex, |
| 125 |
callBacks: *mut CFXMLParserCallBacks, |
| 126 |
context: *mut CFXMLParserContext, |
| 127 |
) -> CFXMLParserRef; |
| 128 |
pub fn CFXMLParserGetContext(parser: CFXMLParserRef, context: *mut CFXMLParserContext); |
| 129 |
pub fn CFXMLParserGetCallBacks(parser: CFXMLParserRef, callBacks: *mut CFXMLParserCallBacks); |
| 130 |
pub fn CFXMLParserGetSourceURL(parser: CFXMLParserRef) -> CFURLRef; |
| 131 |
pub fn CFXMLParserGetLocation(parser: CFXMLParserRef) -> CFIndex; |
| 132 |
pub fn CFXMLParserGetLineNumber(parser: CFXMLParserRef) -> CFIndex; |
| 133 |
pub fn CFXMLParserGetDocument(parser: CFXMLParserRef) -> *mut c_void; |
| 134 |
pub fn CFXMLParserGetStatusCode(parser: CFXMLParserRef) -> CFXMLParserStatusCode; |
| 135 |
pub fn CFXMLParserCopyErrorDescription(parser: CFXMLParserRef) -> CFStringRef; |
| 136 |
pub fn CFXMLParserAbort( |
| 137 |
parser: CFXMLParserRef, |
| 138 |
errorCode: CFXMLParserStatusCode, |
| 139 |
errorDescription: CFStringRef, |
| 140 |
); |
| 141 |
pub fn CFXMLParserParse(parser: CFXMLParserRef) -> Boolean; |
| 142 |
pub fn CFXMLTreeCreateFromData( |
| 143 |
allocator: CFAllocatorRef, |
| 144 |
xmlData: CFDataRef, |
| 145 |
dataSource: CFURLRef, |
| 146 |
parseOptions: CFOptionFlags, |
| 147 |
versionOfNodes: CFIndex, |
| 148 |
) -> CFXMLTreeRef; |
| 149 |
pub fn CFXMLTreeCreateFromDataWithError( |
| 150 |
allocator: CFAllocatorRef, |
| 151 |
xmlData: CFDataRef, |
| 152 |
dataSource: CFURLRef, |
| 153 |
parseOptions: CFOptionFlags, |
| 154 |
versionOfNodes: CFIndex, |
| 155 |
errorDict: *mut CFDictionaryRef, |
| 156 |
) -> CFXMLTreeRef; |
| 157 |
pub fn CFXMLTreeCreateWithDataFromURL( |
| 158 |
allocator: CFAllocatorRef, |
| 159 |
dataSource: CFURLRef, |
| 160 |
parseOptions: CFOptionFlags, |
| 161 |
versionOfNodes: CFIndex, |
| 162 |
) -> CFXMLTreeRef; |
| 163 |
pub fn CFXMLTreeCreateXMLData(allocator: CFAllocatorRef, xmlTree: CFXMLTreeRef) -> CFDataRef; |
| 164 |
pub fn CFXMLCreateStringByEscapingEntities( |
| 165 |
allocator: CFAllocatorRef, |
| 166 |
string: CFStringRef, |
| 167 |
entitiesDictionary: CFDictionaryRef, |
| 168 |
) -> CFStringRef; |
| 169 |
pub fn CFXMLCreateStringByUnescapingEntities( |
| 170 |
allocator: CFAllocatorRef, |
| 171 |
string: CFStringRef, |
| 172 |
entitiesDictionary: CFDictionaryRef, |
| 173 |
) -> CFStringRef; |
| 174 |
} |