1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2023 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::os::raw::{c_char, c_void};

use crate::array::CFArrayRef;
use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID};
use crate::dictionary::CFDictionaryRef;
use crate::string::{CFStringEncoding, CFStringRef};
use crate::tree::CFTreeRef;
use crate::url::CFURLRef;

#[repr(C)]
pub struct __CFXMLNode(c_void);

pub type CFXMLNodeRef = *mut __CFXMLNode;
pub type CFXMLTreeRef = CFTreeRef;

pub const kCFXMLNodeCurrentVersion: CFIndex = 1;

pub type CFXMLNodeTypeCode = CFIndex;
pub const kCFXMLNodeTypeDocument: CFXMLNodeTypeCode = 1;
pub const kCFXMLNodeTypeElement: CFXMLNodeTypeCode = 2;
pub const kCFXMLNodeTypeAttribute: CFXMLNodeTypeCode = 3;
pub const kCFXMLNodeTypeProcessingInstruction: CFXMLNodeTypeCode = 4;
pub const kCFXMLNodeTypeComment: CFXMLNodeTypeCode = 5;
pub const kCFXMLNodeTypeText: CFXMLNodeTypeCode = 6;
pub const kCFXMLNodeTypeCDATASection: CFXMLNodeTypeCode = 7;
pub const kCFXMLNodeTypeDocumentFragment: CFXMLNodeTypeCode = 8;
pub const kCFXMLNodeTypeEntity: CFXMLNodeTypeCode = 9;
pub const kCFXMLNodeTypeEntityReference: CFXMLNodeTypeCode = 10;
pub const kCFXMLNodeTypeDocumentType: CFXMLNodeTypeCode = 11;
pub const kCFXMLNodeTypeWhitespace: CFXMLNodeTypeCode = 12;
pub const kCFXMLNodeTypeNotation: CFXMLNodeTypeCode = 13;
pub const kCFXMLNodeTypeElementTypeDeclaration: CFXMLNodeTypeCode = 14;
pub const kCFXMLNodeTypeAttributeListDeclaration: CFXMLNodeTypeCode = 15;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLElementInfo {
    pub attributes: CFDictionaryRef,
    pub attributeOrder: CFArrayRef,
    pub isEmpty: Boolean,
    pub _reserved: [c_char; 3],
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLProcessingInstructionInfo {
    pub dataString: CFStringRef,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLDocumentInfo {
    pub sourceURL: CFURLRef,
    pub encoding: CFStringEncoding,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLExternalID {
    pub systemID: CFURLRef,
    pub publicID: CFStringRef,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLDocumentTypeInfo {
    pub externalID: CFXMLExternalID,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLNotationInfo {
    pub externalID: CFXMLExternalID,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLElementTypeDeclarationInfo {
    pub contentDescription: CFStringRef,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLAttributeDeclarationInfo {
    pub attributeName: CFStringRef,
    pub typeString: CFStringRef,
    pub defaultString: CFStringRef,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLAttributeListDeclarationInfo {
    pub numberOfAttributes: CFIndex,
    pub attributes: *mut CFXMLAttributeDeclarationInfo,
}

pub type CFXMLEntityTypeCode = CFIndex;
pub const kCFXMLEntityTypeParameter: CFXMLEntityTypeCode = 0;
pub const kCFXMLEntityTypeParsedInternal: CFXMLEntityTypeCode = 1;
pub const kCFXMLEntityTypeParsedExternal: CFXMLEntityTypeCode = 2;
pub const kCFXMLEntityTypeUnparsed: CFXMLEntityTypeCode = 3;
pub const kCFXMLEntityTypeCharacter: CFXMLEntityTypeCode = 4;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLEntityInfo {
    pub entityType: CFXMLEntityTypeCode,
    pub replacementText: CFStringRef,
    pub entityID: CFXMLExternalID,
    pub notationName: CFStringRef,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct CFXMLEntityReferenceInfo {
    pub entityType: CFXMLEntityTypeCode,
}

extern "C" {
    /*
     * CFXMLNode.h
     */
    pub fn CFXMLNodeGetTypeID() -> CFTypeID;
    pub fn CFXMLNodeCreate(
        alloc: CFAllocatorRef,
        xmlType: CFXMLNodeTypeCode,
        dataString: CFStringRef,
        additionalInfoPtr: *const c_void,
        version: CFIndex,
    ) -> CFXMLNodeRef;
    pub fn CFXMLNodeCreateCopy(alloc: CFAllocatorRef, origNode: CFXMLNodeRef) -> CFXMLNodeRef;
    pub fn CFXMLNodeGetTypeCode(node: CFXMLNodeRef) -> CFXMLNodeTypeCode;
    pub fn CFXMLNodeGetString(node: CFXMLNodeRef) -> CFStringRef;
    pub fn CFXMLNodeGetInfoPtr(node: CFXMLNodeRef) -> *const c_void;
    pub fn CFXMLNodeGetVersion(node: CFXMLNodeRef) -> CFIndex;
    pub fn CFXMLTreeCreateWithNode(alloc: CFAllocatorRef, node: CFXMLNodeRef) -> CFXMLTreeRef;
    pub fn CFXMLTreeGetNode(xmlTree: CFXMLTreeRef) -> CFXMLNodeRef;
}