#![allow(unsafe_code)]
use crate::hton::{BinlogCommand, BinlogFunc};
use crate::panic_guard::FfiBoundary;
use crate::runtime;
use crate::runtime::FfiPtr;
use crate::sys;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__binlog_func(thd: *const sys::THD, func: u32) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.binlog_func(thd_ref, BinlogFunc::from_raw(func)),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
#[allow(clippy::too_many_arguments)]
pub unsafe extern "C" fn rust__hton__binlog_log_query(
thd: *const sys::THD,
command: u32,
query: *const u8,
query_len: usize,
db: *const u8,
db_len: usize,
table: *const u8,
table_len: usize,
) {
FfiBoundary::run_void(|| {
let query_str = match unsafe { FfiPtr::bytes_to_str(query, query_len) } {
Ok(s) => s,
Err(_) => return,
};
let db_str = match unsafe { FfiPtr::bytes_to_str(db, db_len) } {
Ok(s) => s,
Err(_) => return,
};
let table_str = match unsafe { FfiPtr::bytes_to_str(table, table_len) } {
Ok(s) => s,
Err(_) => return,
};
let thd_ref = unsafe { thd.as_ref() };
if let Some(h) = runtime::handlerton() {
h.binlog_log_query(
thd_ref,
BinlogCommand::from_raw(command),
query_str,
db_str,
table_str,
);
}
});
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__acl_notify(thd: *const sys::THD) {
FfiBoundary::run_void(|| {
let thd_ref = unsafe { thd.as_ref() };
if let Some(h) = runtime::handlerton() {
h.acl_notify(thd_ref);
}
});
}