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
use std::ffi::{c_char, c_double, c_int, c_long, c_longlong, c_uint, c_ulong, c_ulonglong};

use super::{mysql_var_check_func, mysql_var_update_func, TYPELIB};

// Defined in service_encryption.h but not imported because of tilde syntax
pub const ENCRYPTION_KEY_VERSION_INVALID: c_uint = !0;

#[allow(dead_code)] // not sure why this lint hits
pub const PLUGIN_VAR_MASK: u32 = super::PLUGIN_VAR_READONLY
    | super::PLUGIN_VAR_NOSYSVAR
    | super::PLUGIN_VAR_NOCMDOPT
    | super::PLUGIN_VAR_NOCMDARG
    | super::PLUGIN_VAR_OPCMDARG
    | super::PLUGIN_VAR_RQCMDARG
    | super::PLUGIN_VAR_DEPRECATED
    | super::PLUGIN_VAR_MEMALLOC;

// We hand write these stucts because the definition is tricky, not all fields are
// always present

// no support for THD yet
macro_rules! declare_sysvar_type {
    (@common $name:ident: $(#[$doc:meta] $fname:ident: $fty:ty),* $(,)*) => {
        // Common implementation
        #[repr(C)]
        #[derive(Debug)]
        pub struct $name {
            /// Variable flags
            pub flags: c_int,
            /// Name of the variable
            pub name: *const c_char,
            /// Variable description
            pub comment: *const c_char,
            /// Function for getting the variable
            pub check: mysql_var_check_func,
            /// Function for setting the variable
            pub update: mysql_var_update_func,

            // Repeated fields
            $(
                #[$doc]
                pub $fname: $fty
            ),*
        }
    };
    (basic: $name:ident, $ty:ty) => {
        // A "basic" sysvar
        declare_sysvar_type!{
            @common $name:
            #[doc = "Pointer to the value"]
            value: *mut $ty,
            #[doc = "Default value"]
            def_val: $ty,
        }
    };
    (const basic: $name:ident, $ty:ty) => {
        // A "basic" sysvar
        declare_sysvar_type!{
            @common $name:
            #[doc = "Pointer to the value"]
            value: *const $ty,
            #[doc = "Default value"]
            def_val: $ty,
        }
    };
    (simple: $name:ident, $ty:ty) => {
        // A "simple" sysvar, with minimum maximum and block size
        declare_sysvar_type!{
            @common $name:
            #[doc = "Pointer to the value"]
            value: *mut $ty,
            #[doc = "Default value"]
            def_val: $ty,
            #[doc = "Min value"]
            min_val: $ty,
            #[doc = "Max value"]
            max_val: $ty,
            #[doc = "Block size"]
            blk_sz: $ty,
        }
    };
    (typelib: $name:ident, $ty:ty) => {
        // A "typelib" sysvar
        declare_sysvar_type!{
            @common $name:
            #[doc = "Pointer to the value"]
            value: *mut $ty,
            #[doc = "Default value"]
            def_val: $ty,
            #[doc = "Typelib"]
            typelib: *const TYPELIB
        }
    };


    // (typelib: $name:ident, $ty:ty) => {

    // };
    // (thd: $name:ident, $ty:ty) => {

    // };
}

declare_sysvar_type!(@common sysvar_common_t:);
declare_sysvar_type!(basic: sysvar_bool_t, bool);
declare_sysvar_type!(basic: sysvar_str_t, *mut c_char);
declare_sysvar_type!(typelib: sysvar_enum_t, c_ulong);
declare_sysvar_type!(typelib: sysvar_set_t, c_ulonglong);
declare_sysvar_type!(simple: sysvar_int_t, c_int);
declare_sysvar_type!(simple: sysvar_long_t, c_long);
declare_sysvar_type!(simple: sysvar_longlong_t, c_longlong);
declare_sysvar_type!(simple: sysvar_uint_t, c_uint);
declare_sysvar_type!(simple: sysvar_ulong_t, c_ulong);
declare_sysvar_type!(simple: sysvar_ulonglong_t, c_ulonglong);
declare_sysvar_type!(simple: sysvar_double_t, c_double);

// declare_sysvar_type!(thdbasic: thdvar_bool_t, bool);
// declare_sysvar_type!(thdbasic: thdvar_str_t, *mut c_char);
// declare_sysvar_type!(typelib: sysvar_enum_t, c_ulong);
// declare_sysvar_type!(typelib: sysvar_set_t, c_ulonglong);

// type THDVAR_FUNC<T> = Option<unsafe extern "C" fn(thd: *const c_void, offset: c_int) -> *mut T>;