1use std::ffi::c_void;
2use std::os::raw::c_ulong;
3
4type THD = c_void;
6
7#[derive(Eq, PartialEq, Copy, Clone)]
9#[cfg_attr(test, derive(Debug))]
10#[non_exhaustive]
11#[repr(i32)]
12pub enum PluginType {
13 Udf = 0,
15
16 Storage = 1,
18}
19
20#[derive(Eq, PartialEq, Copy, Clone)]
22#[cfg_attr(test, derive(Debug))]
23#[repr(i32)]
24pub enum License {
25 Proprietary = 0,
27
28 Gpl = 1,
30
31 Bsd = 2,
33}
34
35#[derive(Copy, Clone)]
37#[cfg_attr(test, derive(Debug))]
38#[repr(C)]
39pub struct StorageEngineInfo {
40 pub interface_version: i32,
42}
43
44#[derive(Eq, PartialEq, Copy, Clone)]
45#[cfg_attr(test, derive(Debug))]
46#[allow(missing_docs)]
47#[repr(C)]
48pub enum ShowCompOption {
49 Yes,
50 No,
51 Disabled,
52}
53
54#[derive(Eq, PartialEq, Copy, Clone)]
56#[cfg_attr(test, derive(Debug))]
57#[allow(missing_docs)]
58#[repr(C)]
59pub enum LegacyDbType {
60 Unknown = 0,
61 DiabIsam = 1,
62 Hash,
63 MIsam,
64 PIsam,
65 RmsIsam,
66 Heam,
67 Isam,
68 MrgIsam,
69 MyIsam,
70 MrgMyIsam,
71 BerkeleyDb,
72 InnoDb,
73 Gemini,
74 NDbCluster,
75 ExampleDb,
76 ArchiveDb,
77 CsvDb,
78 FederatedDb,
79 BlackholeDb,
80 PartitionDb,
81 Binlog,
83 Solid,
84 Pbxt,
85 TableFunction,
86 MemCache,
87 Falcon,
88 Maria,
89 PerformanceSchema,
91 TempTable,
92 FirstDynamic = 42,
93 Default = 127, }
95
96pub type CloseConnectionFunc = extern "C" fn(hton: *mut Handlerton, thd: *mut THD) -> i32;
98
99pub type KillConnectionFunc = extern "C" fn(hton: *mut Handlerton, thd: *mut THD);
101
102pub type PreDdShutdownFunc = extern "C" fn(hton: *mut Handlerton);
104
105#[derive(Copy, Clone)]
107#[cfg_attr(test, derive(Debug))]
108#[allow(missing_docs)]
109#[repr(C)]
110pub struct Handlerton {
111 pub state: ShowCompOption,
113
114 pub db_type: LegacyDbType,
116
117 pub slot: u32,
119
120 pub savepoint_offset: u32,
122
123 pub close_connection: *const CloseConnectionFunc,
124
125 pub kill_connection: *const KillConnectionFunc,
126
127 pub pre_dd_shutdown: *const PreDdShutdownFunc,
128}
129
130pub type InitFunc = extern "C" fn(*mut c_void) -> i32;
132
133pub type CheckUninstallFunc = extern "C" fn(*mut c_void) -> i32;
135
136pub type DeinitFunc = extern "C" fn(*mut c_void) -> i32;
138
139#[cfg_attr(test, derive(Debug))]
141#[repr(C)]
142pub struct Plugin {
143 pub plugin_type: PluginType,
145
146 pub info: *const c_void,
151
152 pub name: *const u8,
154
155 pub author: *const u8,
157
158 pub descr: *const u8,
160
161 pub license: License,
163
164 pub init: *const InitFunc,
166
167 pub check_uninstall: *const CheckUninstallFunc,
169
170 pub deinit: *const DeinitFunc,
172
173 pub version: u32,
175
176 pub status_vars: *const c_void,
178
179 pub system_vars: *const c_void,
181
182 pub reserved: *const c_void,
184
185 pub flags: c_ulong,
187}
188
189unsafe impl Sync for Plugin {}
190
191impl Plugin {
192 pub const fn zero() -> Self {
194 Self {
195 plugin_type: PluginType::Udf,
196 info: std::ptr::null_mut(),
197 name: std::ptr::null(),
198 author: std::ptr::null(),
199 descr: std::ptr::null(),
200 license: License::Proprietary,
201 init: std::ptr::null(),
202 check_uninstall: std::ptr::null(),
203 deinit: std::ptr::null(),
204 version: 0,
205 status_vars: std::ptr::null(),
206 system_vars: std::ptr::null(),
207 reserved: std::ptr::null(),
208 flags: 0,
209 }
210 }
211}
212
213#[cfg(test)]
214mod tests {
215 use std::ffi::c_void;
216
217 use crate::constants::MYSQL_HANDLERTON_INTERFACE_VERSION;
218 use crate::types::{License, Plugin, PluginType, StorageEngineInfo};
219
220 #[test]
221 fn create_plugin_struct() {
222 let info = StorageEngineInfo {
223 interface_version: MYSQL_HANDLERTON_INTERFACE_VERSION,
224 };
225
226 let plugin = Plugin {
227 plugin_type: PluginType::Storage,
228 info: &info as *const _ as *const c_void,
229 name: b"example\0" as *const u8,
230 author: b"Felix Bytow\0" as *const u8,
231 descr: b"Example storage engine in Rust\0" as *const u8,
232 license: License::Bsd,
233 ..Plugin::zero()
234 };
235
236 let _plugins: [Plugin; 2] = [
237 plugin,
238 Plugin::zero(),
239 ];
240 }
241}