falco_plugin/plugin/
event.rs

1use falco_event::events::RawEvent;
2use std::ffi::CStr;
3
4pub use falco_plugin_api::ss_plugin_event_input;
5
6/// # An event from which additional data may be extracted
7#[derive(Debug)]
8pub struct EventInput(pub(crate) ss_plugin_event_input);
9
10impl EventInput {
11    /// # Get the event
12    ///
13    /// This method parses the raw event data into a [`RawEvent`] instance,
14    /// which can be later converted into a specific event type.
15    pub fn event(&self) -> std::io::Result<RawEvent> {
16        unsafe { RawEvent::from_ptr(self.0.evt as *const _) }
17    }
18
19    /// # Get the event source
20    ///
21    /// Return the event source (if any)
22    pub fn source(&self) -> Option<&CStr> {
23        unsafe {
24            if self.0.evtsrc.is_null() {
25                None
26            } else {
27                Some(CStr::from_ptr(self.0.evtsrc))
28            }
29        }
30    }
31
32    /// # Get the event number
33    ///
34    /// Return the event number as determined by the plugin framework
35    pub fn event_number(&self) -> usize {
36        self.0.evtnum as usize
37    }
38}