Added symbol names and (TODO) signatures.

Added optional feature for C-interface based plugins (TODO: Create the C interface)

Fortune for rng's current commit: Curse − 凶
plugin
Avril 2 years ago
parent 7e8a4ab553
commit b566caa361
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -20,7 +20,7 @@ libc = { version = "0.2.126", optional = true }
regex = { version = "1.6.0", optional = true } regex = { version = "1.6.0", optional = true }
[features] [features]
default = ["plugin"] default = ["plugin-ffi"]
# Dynamically allocate and populate all memory needed for `--bytes` at runtime instead of streaming in fixed size blocks. # Dynamically allocate and populate all memory needed for `--bytes` at runtime instead of streaming in fixed size blocks.
# #
@ -29,3 +29,6 @@ bytes-dynamic = []
# Allow plugin-loading at runtime with `[@<plugin-name>]... <options...>` # Allow plugin-loading at runtime with `[@<plugin-name>]... <options...>`
plugin = ["libc", "bitflags", "lazy_static", "regex"] plugin = ["libc", "bitflags", "lazy_static", "regex"]
# Allow non-Rust (C interface) plugin symbol resolution.
plugin-ffi = ["plugin"]

@ -1,3 +1,54 @@
//! Loads dynamic object plugins for `rngcli` //! Loads dynamic object plugins for `rngcli` and loads the correct symbol entry point for adding the plugin.
use super::*; use super::*;
/// The expected function signatures and ABIs of loader/unloader functions found via symbol lookup.
pub mod signatures {
/// The expected signature of the plugin's loader function symbol.
pub type PluginLoaderFunction = unsafe extern "Rust" fn () -> (); //TODO
/// The expected signature of the plugin's unloader function symbol (if it exists.)
pub type PluginUnloaderFunction = unsafe extern "Rust" fn () -> (); //TODO
#[cfg(feature="plugin-ffi")] pub use super::ffi::signatures::*;
}
/// Contains C-interface symbols and their corresponding signatures.
#[cfg(feature="plugin-ffi")]
mod ffi {
/// The names of various symbols needed for lookups in a C-interface plugin's executable object.
///
/// The means of lookup is via `dlsym()`.
pub mod symbols {
/// The C function symbol name to search for if the Rust one was not found which handles registering the plugin.
///
/// The signature of this function **must** be `ForeignPluginLoaderFunction`.
pub static FFI_PLUGIN_SYMBOL_NAME_ADD: &'static str = "_rngcli_plugin_add_c";
/// The C function symbol name to search for if the Rust one was not found which handles unloading the plugin. It is optional to include this (as the Rust one is too.)
/// The signature of this function **must** be `ForeignPluginUnloaderFunction`.
pub static FFI_PLUGIN_SYMBOL_NAME_REMOVE: &'static str = "_rngcli_plugin_remove_c";
}
/// The expected function signatures of a C-interface plugin's loader/unloader symbols found via symbol lookup.
pub mod signatures {
/// The expected signature of the C-interface plugin's loader function symbol.
pub type ForeignPluginLoaderFunction = unsafe extern "C" fn () -> (); //TODO
/// The expected signature of the C-interface plugin's unloader function symbol (if it exists.)
pub type ForeignPluginUnloaderFunction = unsafe extern "C" fn () -> (); //TODO
}
}
/// The names of various symbols needed for lookups in a plugin's executable object.
///
/// The means of the lookup is via `dlsym()`.
pub mod symbols {
/// The Rust function symbol name (non-mangled) to search for in the plugin executable object which handles registering the plugin.
///
/// The signature of this function **must** be `PluginLoaderFunction`.
pub static RUST_PLUGIN_SYMBOL_NAME_ADD: &'static str = "rngcli_plugin_add";
/// The (optional) Rust function symbol name (non-mangled) to search for in the plugin which is ran when the plugin is unloaded.
///
/// The signature of this function **must** be `PluginUnloaderFunction`.
pub static RUST_PLUGIN_SYMBOL_NAME_REMOVE: &'static str = "rngcli_plugin_remove";
#[cfg(feature="plugin-ffi")] pub use super::ffi::symbols::*;
}
use signatures::*;
//TODO: Figure out what signature to use.

@ -209,9 +209,8 @@ struct PathLookup {
impl PathLookup impl PathLookup
{ {
#[inline] #[inline]
pub fn check_valid_path<const Trusted: bool>(path: impl AsRef<Path>) -> bool pub fn check_valid_path<const TRUSTED: bool>(path: impl AsRef<Path>) -> bool
{ {
#[inline(always)] #[inline(always)]
fn regex_builder(pattern: impl AsRef<str>) -> Regex { fn regex_builder(pattern: impl AsRef<str>) -> Regex {
@ -282,7 +281,7 @@ impl PathLookup
// } // }
// } // }
let (matcher, checker) = if Trusted { let (matcher, checker) = if TRUSTED {
// Trusted path lookup // Trusted path lookup
(match_any(TRUSTED_EXT_REGEX_MAP.iter()), None)//&NoChecker) (match_any(TRUSTED_EXT_REGEX_MAP.iter()), None)//&NoChecker)
} else { } else {

Loading…
Cancel
Save