Skip to content

Commit 28767f8

Browse files
sys: Introduce CFXML functionality
Implements CFXMLNode, CFXMLTree and CFXMLParser functions and related constants and structures. All of them are considered deprecated, even though these may be the last bits of fully implemented core-foundation-sys crate (with functionality of macOS 10.7 and 10.8 obviously).
1 parent 423930b commit 28767f8

File tree

3 files changed

+260
-1
lines changed

3 files changed

+260
-1
lines changed

core-foundation-sys/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub mod error;
3737
pub mod filedescriptor;
3838
pub mod file_security;
3939
pub mod locale;
40+
pub mod mach_port;
4041
pub mod messageport;
4142
pub mod notification_center;
4243
pub mod number;
@@ -57,4 +58,7 @@ pub mod url_enumerator;
5758
#[cfg(target_os = "macos")]
5859
pub mod user_notification;
5960
pub mod uuid;
60-
pub mod mach_port;
61+
#[cfg(target_os = "macos")]
62+
pub mod xml_node;
63+
#[cfg(target_os = "macos")]
64+
pub mod xml_parser;

core-foundation-sys/src/xml_node.rs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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, c_char};
11+
12+
use base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};
13+
use tree::CFTreeRef;
14+
use dictionary::CFDictionaryRef;
15+
use array::CFArrayRef;
16+
use string::{CFStringRef, CFStringEncoding};
17+
use url::CFURLRef;
18+
19+
#[repr(C)]
20+
pub struct __CFXMLNode(c_void);
21+
22+
pub type CFXMLNodeRef = *mut __CFXMLNode;
23+
pub type CFXMLTreeRef = CFTreeRef;
24+
25+
pub const kCFXMLNodeCurrentVersion: CFIndex = 1;
26+
27+
pub type CFXMLNodeTypeCode = CFIndex;
28+
pub const kCFXMLNodeTypeDocument: CFXMLNodeTypeCode = 1;
29+
pub const kCFXMLNodeTypeElement: CFXMLNodeTypeCode = 2;
30+
pub const kCFXMLNodeTypeAttribute: CFXMLNodeTypeCode = 3;
31+
pub const kCFXMLNodeTypeProcessingInstruction: CFXMLNodeTypeCode = 4;
32+
pub const kCFXMLNodeTypeComment: CFXMLNodeTypeCode = 5;
33+
pub const kCFXMLNodeTypeText: CFXMLNodeTypeCode = 6;
34+
pub const kCFXMLNodeTypeCDATASection: CFXMLNodeTypeCode = 7;
35+
pub const kCFXMLNodeTypeDocumentFragment: CFXMLNodeTypeCode = 8;
36+
pub const kCFXMLNodeTypeEntity: CFXMLNodeTypeCode = 9;
37+
pub const kCFXMLNodeTypeEntityReference: CFXMLNodeTypeCode = 10;
38+
pub const kCFXMLNodeTypeDocumentType: CFXMLNodeTypeCode = 11;
39+
pub const kCFXMLNodeTypeWhitespace: CFXMLNodeTypeCode = 12;
40+
pub const kCFXMLNodeTypeNotation: CFXMLNodeTypeCode = 13;
41+
pub const kCFXMLNodeTypeElementTypeDeclaration: CFXMLNodeTypeCode = 14;
42+
pub const kCFXMLNodeTypeAttributeListDeclaration: CFXMLNodeTypeCode = 15;
43+
44+
#[repr(C)]
45+
#[derive(Debug, Clone, Copy)]
46+
pub struct CFXMLElementInfo {
47+
pub attributes: CFDictionaryRef,
48+
pub attributeOrder: CFArrayRef,
49+
pub isEmpty: Boolean,
50+
pub _reserved: [c_char; 3]
51+
}
52+
53+
#[repr(C)]
54+
#[derive(Debug, Clone, Copy)]
55+
pub struct CFXMLProcessingInstructionInfo {
56+
pub dataString: CFStringRef
57+
}
58+
59+
#[repr(C)]
60+
#[derive(Debug, Clone, Copy)]
61+
pub struct CFXMLDocumentInfo {
62+
pub sourceURL: CFURLRef,
63+
pub encoding: CFStringEncoding
64+
}
65+
66+
#[repr(C)]
67+
#[derive(Debug, Clone, Copy)]
68+
pub struct CFXMLExternalID {
69+
pub systemID: CFURLRef,
70+
pub publicID: CFStringRef
71+
}
72+
73+
#[repr(C)]
74+
#[derive(Debug, Clone, Copy)]
75+
pub struct CFXMLDocumentTypeInfo {
76+
pub externalID: CFXMLExternalID
77+
}
78+
79+
#[repr(C)]
80+
#[derive(Debug, Clone, Copy)]
81+
pub struct CFXMLNotationInfo {
82+
pub externalID: CFXMLExternalID
83+
}
84+
85+
#[repr(C)]
86+
#[derive(Debug, Clone, Copy)]
87+
pub struct CFXMLElementTypeDeclarationInfo {
88+
pub contentDescription: CFStringRef
89+
}
90+
91+
#[repr(C)]
92+
#[derive(Debug, Clone, Copy)]
93+
pub struct CFXMLAttributeDeclarationInfo {
94+
pub attributeName: CFStringRef,
95+
pub typeString: CFStringRef,
96+
pub defaultString: CFStringRef
97+
}
98+
99+
#[repr(C)]
100+
#[derive(Debug, Clone, Copy)]
101+
pub struct CFXMLAttributeListDeclarationInfo {
102+
pub numberOfAttributes: CFIndex,
103+
pub attributes: *mut CFXMLAttributeDeclarationInfo
104+
}
105+
106+
pub type CFXMLEntityTypeCode = CFIndex;
107+
pub const kCFXMLEntityTypeParameter: CFXMLEntityTypeCode = 0;
108+
pub const kCFXMLEntityTypeParsedInternal: CFXMLEntityTypeCode = 1;
109+
pub const kCFXMLEntityTypeParsedExternal: CFXMLEntityTypeCode = 2;
110+
pub const kCFXMLEntityTypeUnparsed: CFXMLEntityTypeCode = 3;
111+
pub const kCFXMLEntityTypeCharacter: CFXMLEntityTypeCode = 4;
112+
113+
#[repr(C)]
114+
#[derive(Debug, Clone, Copy)]
115+
pub struct CFXMLEntityInfo {
116+
pub entityType: CFXMLEntityTypeCode,
117+
pub replacementText: CFStringRef,
118+
pub entityID: CFXMLExternalID,
119+
pub notationName: CFStringRef
120+
}
121+
122+
#[repr(C)]
123+
#[derive(Debug, Clone, Copy)]
124+
pub struct CFXMLEntityReferenceInfo {
125+
pub entityType: CFXMLEntityTypeCode
126+
}
127+
128+
extern {
129+
/*
130+
* CFXMLNode.h
131+
*/
132+
pub fn CFXMLNodeGetTypeID() -> CFTypeID;
133+
pub fn CFXMLNodeCreate(alloc: CFAllocatorRef, xmlType: CFXMLNodeTypeCode, dataString: CFStringRef, additionalInfoPtr: *const c_void, version: CFIndex) -> CFXMLNodeRef;
134+
pub fn CFXMLNodeCreateCopy(alloc: CFAllocatorRef, origNode: CFXMLNodeRef) -> CFXMLNodeRef;
135+
pub fn CFXMLNodeGetTypeCode(node: CFXMLNodeRef) -> CFXMLNodeTypeCode;
136+
pub fn CFXMLNodeGetString(node: CFXMLNodeRef) -> CFStringRef;
137+
pub fn CFXMLNodeGetInfoPtr(node: CFXMLNodeRef) -> *const c_void;
138+
pub fn CFXMLNodeGetVersion(node: CFXMLNodeRef) -> CFIndex;
139+
pub fn CFXMLTreeCreateWithNode(alloc: CFAllocatorRef, node: CFXMLNodeRef) -> CFXMLTreeRef;
140+
pub fn CFXMLTreeGetNode(xmlTree: CFXMLTreeRef) -> CFXMLNodeRef;
141+
}

core-foundation-sys/src/xml_parser.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 base::{CFOptionFlags, CFIndex, Boolean, CFAllocatorRef, CFTypeID};
13+
use xml_node::{CFXMLNodeRef, CFXMLTreeRef, CFXMLExternalID};
14+
use data::CFDataRef;
15+
use string::CFStringRef;
16+
use url::CFURLRef;
17+
use dictionary::CFDictionaryRef;
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 = extern "C" fn (parser: CFXMLParserRef, nodeDesc: CFXMLNodeRef, info: *mut c_void) -> *mut c_void;
55+
pub type CFXMLParserAddChildCallBack = extern "C" fn (parser: CFXMLParserRef, parent: *mut c_void, child: *mut c_void, info: *mut c_void);
56+
pub type CFXMLParserEndXMLStructureCallBack = extern "C" fn (parser: CFXMLParserRef, xmlType: *mut c_void, info: *mut c_void);
57+
pub type CFXMLParserResolveExternalEntityCallBack = extern "C" fn (parser: CFXMLParserRef, extID: *mut CFXMLExternalID, info: *mut c_void) -> CFDataRef;
58+
pub type CFXMLParserHandleErrorCallBack = extern "C" fn (parser: CFXMLParserRef, error: CFXMLParserStatusCode, info: *mut c_void) -> Boolean;
59+
60+
#[repr(C)]
61+
#[derive(Debug, Clone, Copy)]
62+
pub struct CFXMLParserCallBacks {
63+
pub version: CFIndex,
64+
pub createXMLStructure: CFXMLParserCreateXMLStructureCallBack,
65+
pub addChild: CFXMLParserAddChildCallBack,
66+
pub endXMLStructure: CFXMLParserEndXMLStructureCallBack,
67+
pub resolveExternalEntity: CFXMLParserResolveExternalEntityCallBack,
68+
pub handleError: CFXMLParserHandleErrorCallBack,
69+
}
70+
71+
pub type CFXMLParserRetainCallBack = extern "C" fn(info: *const c_void) -> *const c_void;
72+
pub type CFXMLParserReleaseCallBack = extern "C" fn (info: *const c_void);
73+
pub type CFXMLParserCopyDescriptionCallBack = extern "C" fn(info: *const c_void) -> CFStringRef;
74+
75+
#[repr(C)]
76+
#[derive(Debug, Clone, Copy)]
77+
pub struct CFXMLParserContext {
78+
pub version: CFIndex,
79+
pub info: *mut c_void,
80+
pub retain: CFXMLParserRetainCallBack,
81+
pub release: CFXMLParserReleaseCallBack,
82+
pub copyDescription: CFXMLParserCopyDescriptionCallBack
83+
}
84+
85+
extern {
86+
/*
87+
* CFXMLParser.h
88+
*/
89+
90+
pub static kCFXMLTreeErrorDescription: CFStringRef;
91+
pub static kCFXMLTreeErrorLineNumber: CFStringRef;
92+
pub static kCFXMLTreeErrorLocation: CFStringRef;
93+
pub static kCFXMLTreeErrorStatusCode: CFStringRef;
94+
95+
pub fn CFXMLParserGetTypeID() -> CFTypeID;
96+
pub fn CFXMLParserCreate(allocator: CFAllocatorRef, xmlData: CFDataRef, dataSource: CFURLRef, parseOptions: CFOptionFlags, versionOfNodes: CFIndex, callBacks: *mut CFXMLParserCallBacks, context: *mut CFXMLParserContext) -> CFXMLParserRef;
97+
pub fn CFXMLParserCreateWithDataFromURL(allocator: CFAllocatorRef, dataSource: CFURLRef, parseOptions: CFOptionFlags, versionOfNodes: CFIndex, callBacks: *mut CFXMLParserCallBacks, context: *mut CFXMLParserContext) -> CFXMLParserRef;
98+
pub fn CFXMLParserGetContext(parser: CFXMLParserRef, context: *mut CFXMLParserContext);
99+
pub fn CFXMLParserGetCallBacks(parser: CFXMLParserRef, callBacks: *mut CFXMLParserCallBacks);
100+
pub fn CFXMLParserGetSourceURL(parser: CFXMLParserRef) -> CFURLRef;
101+
pub fn CFXMLParserGetLocation(parser: CFXMLParserRef) -> CFIndex;
102+
pub fn CFXMLParserGetLineNumber(parser: CFXMLParserRef) -> CFIndex;
103+
pub fn CFXMLParserGetDocument(parser: CFXMLParserRef) -> *mut c_void;
104+
pub fn CFXMLParserGetStatusCode(parser: CFXMLParserRef) -> CFXMLParserStatusCode;
105+
pub fn CFXMLParserCopyErrorDescription(parser: CFXMLParserRef) -> CFStringRef;
106+
pub fn CFXMLParserAbort(parser: CFXMLParserRef, errorCode: CFXMLParserStatusCode, errorDescription: CFStringRef);
107+
pub fn CFXMLParserParse(parser: CFXMLParserRef) -> Boolean;
108+
pub fn CFXMLTreeCreateFromData(allocator: CFAllocatorRef, xmlData: CFDataRef, dataSource: CFURLRef, parseOptions: CFOptionFlags, versionOfNodes: CFIndex) -> CFXMLTreeRef;
109+
pub fn CFXMLTreeCreateFromDataWithError(allocator: CFAllocatorRef, xmlData: CFDataRef, dataSource: CFURLRef, parseOptions: CFOptionFlags, versionOfNodes: CFIndex, errorDict: *mut CFDictionaryRef) -> CFXMLTreeRef;
110+
pub fn CFXMLTreeCreateWithDataFromURL(allocator: CFAllocatorRef, dataSource: CFURLRef, parseOptions: CFOptionFlags, versionOfNodes: CFIndex) -> CFXMLTreeRef;
111+
pub fn CFXMLTreeCreateXMLData(allocator: CFAllocatorRef, xmlTree: CFXMLTreeRef) -> CFDataRef;
112+
pub fn CFXMLCreateStringByEscapingEntities(allocator: CFAllocatorRef, string: CFStringRef, entitiesDictionary: CFDictionaryRef) -> CFStringRef;
113+
pub fn CFXMLCreateStringByUnescapingEntities(allocator: CFAllocatorRef, string: CFStringRef, entitiesDictionary: CFDictionaryRef) -> CFStringRef;
114+
}

0 commit comments

Comments
 (0)