core_foundation_sys/
xml_parser.rs

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
10use std::os::raw::c_void;
11
12use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeID};
13use crate::data::CFDataRef;
14use crate::dictionary::CFDictionaryRef;
15use crate::string::CFStringRef;
16use crate::url::CFURLRef;
17use crate::xml_node::{CFXMLExternalID, CFXMLNodeRef, CFXMLTreeRef};
18
19#[repr(C)]
20pub struct __CFXMLParser(c_void);
21
22pub type CFXMLParserRef = *mut __CFXMLParser;
23
24pub type CFXMLParserOptions = CFOptionFlags;
25pub const kCFXMLParserValidateDocument: CFXMLParserOptions = 1 << 0;
26pub const kCFXMLParserSkipMetaData: CFXMLParserOptions = 1 << 1;
27pub const kCFXMLParserReplacePhysicalEntities: CFXMLParserOptions = 1 << 2;
28pub const kCFXMLParserSkipWhitespace: CFXMLParserOptions = 1 << 3;
29pub const kCFXMLParserResolveExternalEntities: CFXMLParserOptions = 1 << 4;
30pub const kCFXMLParserAddImpliedAttributes: CFXMLParserOptions = 1 << 5;
31pub const kCFXMLParserAllOptions: CFXMLParserOptions = 0x00FFFFFF;
32pub const kCFXMLParserNoOptions: CFXMLParserOptions = 0;
33
34pub type CFXMLParserStatusCode = CFIndex;
35pub const kCFXMLStatusParseNotBegun: CFIndex = -2;
36pub const kCFXMLStatusParseInProgress: CFIndex = -1;
37pub const kCFXMLStatusParseSuccessful: CFIndex = 0;
38pub const kCFXMLErrorUnexpectedEOF: CFIndex = 1;
39pub const kCFXMLErrorUnknownEncoding: CFIndex = 2;
40pub const kCFXMLErrorEncodingConversionFailure: CFIndex = 3;
41pub const kCFXMLErrorMalformedProcessingInstruction: CFIndex = 4;
42pub const kCFXMLErrorMalformedDTD: CFIndex = 5;
43pub const kCFXMLErrorMalformedName: CFIndex = 6;
44pub const kCFXMLErrorMalformedCDSect: CFIndex = 7;
45pub const kCFXMLErrorMalformedCloseTag: CFIndex = 8;
46pub const kCFXMLErrorMalformedStartTag: CFIndex = 9;
47pub const kCFXMLErrorMalformedDocument: CFIndex = 10;
48pub const kCFXMLErrorElementlessDocument: CFIndex = 11;
49pub const kCFXMLErrorMalformedComment: CFIndex = 12;
50pub const kCFXMLErrorMalformedCharacterReference: CFIndex = 13;
51pub const kCFXMLErrorMalformedParsedCharacterData: CFIndex = 14;
52pub const kCFXMLErrorNoData: CFIndex = 15;
53
54pub type CFXMLParserCreateXMLStructureCallBack =
55    extern "C" fn(parser: CFXMLParserRef, nodeDesc: CFXMLNodeRef, info: *mut c_void) -> *mut c_void;
56pub type CFXMLParserAddChildCallBack = extern "C" fn(
57    parser: CFXMLParserRef,
58    parent: *mut c_void,
59    child: *mut c_void,
60    info: *mut c_void,
61);
62pub type CFXMLParserEndXMLStructureCallBack =
63    extern "C" fn(parser: CFXMLParserRef, xmlType: *mut c_void, info: *mut c_void);
64pub type CFXMLParserResolveExternalEntityCallBack = extern "C" fn(
65    parser: CFXMLParserRef,
66    extID: *mut CFXMLExternalID,
67    info: *mut c_void,
68) -> CFDataRef;
69pub 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)]
77pub 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
86pub type CFXMLParserRetainCallBack = extern "C" fn(info: *const c_void) -> *const c_void;
87pub type CFXMLParserReleaseCallBack = extern "C" fn(info: *const c_void);
88pub type CFXMLParserCopyDescriptionCallBack = extern "C" fn(info: *const c_void) -> CFStringRef;
89
90#[repr(C)]
91#[derive(Debug, Clone, Copy)]
92pub 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
100extern "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}